Rev 129 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 129 | Rev 384 | ||
---|---|---|---|
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 | ;; ;; |
|
- | 17 | ;; 10.01.2007 Bugfix for checksum function from Paolo Franchetti ;; |
|
- | 18 | ;; ;; |
|
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | 20 | ||
- | 21 | ||
18 | 22 | ||
19 | ;******************************************************************* |
23 | ;******************************************************************* |
20 | ; Interface |
24 | ; Interface |
21 | ; The interfaces defined in ETHERNET.INC plus: |
25 | ; The interfaces defined in ETHERNET.INC plus: |
22 | ; stack_init |
26 | ; stack_init |
23 | ; stack_handler |
27 | ; stack_handler |
24 | ; app_stack_handler |
28 | ; app_stack_handler |
25 | ; app_socket_handler |
29 | ; app_socket_handler |
26 | ; checksum |
30 | ; checksum |
27 | ; |
31 | ; |
28 | ;******************************************************************* |
32 | ;******************************************************************* |
- | 33 | ||
- | 34 | uglobal |
|
- | 35 | StackCounters: |
|
- | 36 | dumped_rx_count: dd 0 |
|
- | 37 | arp_tx_count: dd 0 |
|
- | 38 | arp_rx_count: dd 0 |
|
- | 39 | ip_rx_count: dd 0 |
|
- | 40 | ip_tx_count: dd 0 |
|
- | 41 | endg |
|
- | 42 | ||
- | 43 | ; socket buffers |
|
29 | - | ||
30 | - | ||
31 | - | ||
32 | ; |
- | |
33 | ; IP Packet after reception - Normal IP packet format |
- | |
34 | ; |
- | |
35 | ; 0 1 2 3 |
- | |
36 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
- | |
37 | ; |
- | |
38 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
39 | ;0 |Version| IHL |Type of Service| Total Length | |
- | |
40 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
41 | ;4 | Identification |Flags| Fragment Offset | |
- | |
42 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
43 | ;8 | Time to Live | Protocol | Header Checksum | |
- | |
44 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
45 | ;12 | Source Address | |
- | |
46 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
47 | ;16 | Destination Address | |
- | |
48 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
49 | ; | Data | |
- | |
50 | ; +-+-+-.......... -+ |
- | |
51 | - | ||
52 | - | ||
53 | ; TCP Payload ( Data field in IP datagram ) |
- | |
54 | ; |
- | |
55 | ; 0 1 2 3 |
- | |
56 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
- | |
57 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
58 | ;20 | Source Port | Destination Port | |
- | |
59 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
60 | ;24 | Sequence Number | |
- | |
61 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
62 | ;28 | Acknowledgment Number | |
- | |
63 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
64 | ;32 | Data | |U|A|P|R|S|F| | |
- | |
65 | ; | Offset| Reserved |R|C|S|S|Y|I| Window | |
- | |
66 | ; | | |G|K|H|T|N|N| | |
- | |
67 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
68 | ;36 | Checksum | Urgent Pointer | |
- | |
69 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
70 | ;40 | Options | Padding | |
- | |
71 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
72 | ; | data |
- | |
73 | - | ||
74 | - | ||
75 | ; |
- | |
76 | ; UDP Payload ( Data field in IP datagram ) |
- | |
77 | ; |
- | |
78 | ; 0 1 2 3 |
- | |
79 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
- | |
80 | ; |
- | |
81 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
82 | ; | Source Port | Destination Port | |
- | |
83 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
84 | ; | Length ( UDP Header + Data ) | Checksum | |
- | |
85 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
86 | ; | UDP Data | |
- | |
87 | ; +-+-+-.......... -+ |
- | |
88 | ; |
- | |
89 | - | ||
90 | - | ||
91 | ; |
- | |
92 | ; Socket Descriptor + Buffer |
- | |
93 | ; |
- | |
94 | ; 0 1 2 3 |
- | |
95 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
44 | SOCKETBUFFSIZE equ 4096 ; state + config + buffer. |
96 | ; |
- | |
97 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
98 | ; | Status ( of this buffer ) | |
- | |
99 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
100 | ; | Application Process ID | |
- | |
101 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
102 | ; | Local IP Address | |
- | |
103 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
104 | ; | Local IP Port | Unused ( set to 0 ) | |
- | |
105 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
106 | ; | Remote IP Address | |
- | |
107 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
108 | ; | Remote IP Port | Unused ( set to 0 ) | |
- | |
109 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
110 | ; 24| Rx Data Count INTEL format| |
- | |
111 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
112 | ; 28| TCB STATE INTEL format| |
- | |
113 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
114 | ; 32| TCB Timer (seconds) INTEL format| |
- | |
115 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
116 | ; 36| ISS (Inital Sequence # used by this connection ) INET format| |
- | |
117 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
118 | ; 40| IRS ( Inital Receive Sequence # ) INET format| |
- | |
119 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
120 | ; 44| SND.UNA Seq # of unack'ed sent packets INET format| |
- | |
121 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
122 | ; 48| SND.NXT Next send seq # to use INET format| |
- | |
123 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
124 | ; 52| SND.WND Send window INET format| |
- | |
125 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
126 | ; 56| RCV.NXT Next expected receive sequence # INET format| |
- | |
127 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
128 | ; 60| RCV.WND Receive window INET format| |
- | |
129 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
130 | ; 64| SEG.LEN Segment length INTEL format| |
- | |
131 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
132 | ; 68| SEG.WND Segment window INTEL format| |
- | |
133 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
134 | ; 72| Retransmit queue # NOW WINDOW SIZE TIMER INTEL format| |
- | |
135 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
- | |
136 | ; 76| RX Data | |
- | |
137 | ; +-+-+-.......... -+ |
- | |
138 | - | ||
139 | - | ||
140 | - | ||
141 | ; IP protocol numbers |
- | |
142 | PROTOCOL_ICMP equ 1 |
- | |
143 | PROTOCOL_TCP equ 6 |
45 | SOCKETHEADERSIZE equ 76 ; thus 4096 - SOCKETHEADERSIZE bytes data |
144 | PROTOCOL_UDP equ 17 |
46 | |
145 | 47 | NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20 |
|
146 | 48 | ||
147 | ; TIPBUFF status values |
49 | ; IPBUFF status values |
148 | BUFF_EMPTY equ 0 |
50 | BUFF_EMPTY equ 0 |
149 | BUFF_RX_FULL equ 1 |
51 | BUFF_RX_FULL equ 1 |
150 | BUFF_ALLOCATED equ 2 |
52 | BUFF_ALLOCATED equ 2 |
151 | BUFF_TX_FULL equ 3 |
53 | BUFF_TX_FULL equ 3 |
152 | 54 | ||
153 | NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX |
55 | NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX |
154 | - | ||
155 | SOCK_EMPTY equ 0 ; socket not in use |
- | |
156 | SOCK_OPEN equ 1 ; open issued, but no data sent |
- | |
157 | - | ||
158 | ; TCP opening modes |
- | |
159 | SOCKET_PASSIVE equ 0 |
- | |
160 | SOCKET_ACTIVE equ 1 |
- | |
161 | - | ||
162 | ; TCP TCB states |
- | |
163 | TCB_LISTEN equ 1 |
- | |
164 | TCB_SYN_SENT equ 2 |
- | |
165 | TCB_SYN_RECEIVED equ 3 |
- | |
166 | TCB_ESTABLISHED equ 4 |
- | |
167 | TCB_FIN_WAIT_1 equ 5 |
- | |
168 | TCB_FIN_WAIT_2 equ 6 |
- | |
169 | TCB_CLOSE_WAIT equ 7 |
- | |
170 | TCB_CLOSING equ 8 |
- | |
171 | TCB_LAST_ACK equ 9 |
- | |
172 | TCB_TIME_WAIT equ 10 |
- | |
173 | TCB_CLOSED equ 11 |
- | |
174 | - | ||
175 | TWOMSL equ 10 ; # of secs to wait before closing socket |
- | |
176 | - | ||
177 | ; socket buffers |
- | |
178 | SOCKETBUFFSIZE equ 4096 ; state + config + buffer. |
- | |
179 | SOCKETHEADERSIZE equ 76 ; thus 4096 - SOCKETHEADERSIZE bytes data |
- | |
180 | - | ||
181 | NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20 |
- | |
182 | - | ||
183 | 56 | ||
184 | NUMQUEUES equ 4 |
57 | NUMQUEUES equ 4 |
185 | EMPTY_QUEUE equ 0 |
58 | EMPTY_QUEUE equ 0 |
186 | IPIN_QUEUE equ 1 |
59 | IPIN_QUEUE equ 1 |
187 | IPOUT_QUEUE equ 2 |
60 | IPOUT_QUEUE equ 2 |
188 | NET1OUT_QUEUE equ 3 |
61 | NET1OUT_QUEUE equ 3 |
189 | 62 | ||
190 | NO_BUFFER equ 0xFFFF |
63 | NO_BUFFER equ 0xFFFF |
191 | IPBUFFSIZE equ 1500 ; MTU of an ethernet packet |
64 | IPBUFFSIZE equ 1500 ; MTU of an ethernet packet |
192 | NUMQUEUEENTRIES equ NUM_IPBUFFERS |
65 | NUMQUEUEENTRIES equ NUM_IPBUFFERS |
193 | NUMRESENDENTRIES equ 18 ; Buffers for TCP resend packets |
66 | NUMRESENDENTRIES equ 18 ; Buffers for TCP resend packets |
194 | TCP_RETRIES equ 5 ; Number of times to resend a packet |
- | |
195 | TCP_TIMEOUT equ 10 ; resend if not replied to in x hs |
- | |
196 | 67 | ||
197 | ; 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 |
198 | STACK_DRIVER_STATUS equ 52 |
69 | STACK_DRIVER_STATUS equ 52 |
199 | SOCKET_INTERFACE equ 53 |
70 | SOCKET_INTERFACE equ 53 |
200 | 71 | ||
201 | 72 | ||
202 | ; 128KB allocated for the stack and network driver buffers and other |
73 | ; 128KB allocated for the stack and network driver buffers and other |
203 | ; data requirements |
74 | ; data requirements |
204 | stack_data_start equ 0x700000 |
75 | stack_data_start equ 0x700000 |
205 | eth_data_start equ 0x700000 |
76 | eth_data_start equ 0x700000 |
206 | stack_data equ 0x704000 |
77 | stack_data equ 0x704000 |
207 | stack_data_end equ 0x71ffff |
78 | stack_data_end equ 0x71ffff |
208 | 79 | ||
209 | ; 32 bit word |
80 | ; 32 bit word |
210 | stack_config equ stack_data |
81 | stack_config equ stack_data |
- | 82 | ||
211 | ; 32 bit word - IP Address in network format |
83 | ; 32 bit word - IP Address in network format |
212 | stack_ip equ stack_data + 4 |
84 | stack_ip equ stack_data + 4 |
213 | ; 1 byte. 0 == inactive, 1 = active |
- | |
214 | slip_active equ stack_data + 8 ; no longer used |
- | |
- | 85 | ||
215 | ; 1 byte. 0 == inactive, 1 = active |
86 | ; 1 byte. 0 == inactive, 1 = active |
216 | ethernet_active equ stack_data + 9 |
87 | ethernet_active equ stack_data + 9 |
217 | unused equ stack_data + 10 |
- | |
218 | ; word. Buffer number, -1 if none |
- | |
219 | rx_buff_ptr equ stack_data + 12 |
- | |
220 | ; dword. Buffer number, -1 if none |
- | |
221 | tx_buff_ptr equ stack_data + 16 |
- | |
222 | ; byte. |
88 | |
223 | slip_rx_state equ stack_data + 20 ; no longer used |
- | |
224 | ; byte |
89 | |
225 | slip_tx_state equ stack_data + 21 ; no longer used |
- | |
226 | ; dword. Index into data |
- | |
227 | rx_data_ptr equ stack_data + 22 |
- | |
228 | ; dword. Index into data |
90 | ; TODO :: empty memory area |
229 | tx_data_ptr equ stack_data + 26 |
- | |
230 | ; word. Count of bytes to send |
- | |
231 | tx_msg_len equ stack_data + 30 |
- | |
- | 91 | ||
232 | ; Address of selected socket |
92 | ; Address of selected socket |
233 | sktAddr equ stack_data + 32 |
93 | sktAddr equ stack_data + 32 |
234 | ; Parameter to checksum routine - data ptr |
94 | ; Parameter to checksum routine - data ptr |
235 | checkAdd1 equ stack_data + 36 |
95 | checkAdd1 equ stack_data + 36 |
236 | ; Parameter to checksum routine - 2nd data ptr |
96 | ; Parameter to checksum routine - 2nd data ptr |
237 | checkAdd2 equ stack_data + 40 |
97 | checkAdd2 equ stack_data + 40 |
238 | ; Parameter to checksum routine - data size |
98 | ; Parameter to checksum routine - data size |
239 | checkSize1 equ stack_data + 44 |
99 | checkSize1 equ stack_data + 44 |
240 | ; Parameter to checksum routine - 2nd data size |
100 | ; Parameter to checksum routine - 2nd data size |
241 | checkSize2 equ stack_data + 46 |
101 | checkSize2 equ stack_data + 46 |
242 | ; result of checksum routine |
102 | ; result of checksum routine |
243 | checkResult equ stack_data + 48 |
103 | checkResult equ stack_data + 48 |
244 | 104 | ||
245 | ; 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| |
246 | pseudoHeader equ stack_data + 50 |
106 | pseudoHeader equ stack_data + 50 |
247 | 107 | ||
248 | ; receive and transmit IP buffer allocation |
108 | ; receive and transmit IP buffer allocation |
249 | sockets equ stack_data + 62 |
109 | sockets equ stack_data + 62 |
250 | Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS) |
110 | Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS) |
251 | ; 1560 byte buffer for rx / tx ethernet packets |
111 | ; 1560 byte buffer for rx / tx ethernet packets |
252 | Ether_buffer equ Next_free2 |
112 | Ether_buffer equ Next_free2 |
253 | Next_free3 equ Ether_buffer + 1560 |
113 | Next_free3 equ Ether_buffer + 1518 |
254 | last_1sTick equ Next_free3 |
114 | last_1sTick equ Next_free3 |
255 | IPbuffs equ Next_free3 + 1 |
115 | IPbuffs equ Next_free3 + 1 |
256 | queues equ IPbuffs + ( NUM_IPBUFFERS * IPBUFFSIZE ) |
116 | queues equ IPbuffs + ( NUM_IPBUFFERS * IPBUFFSIZE ) |
257 | queueList equ queues + (2 * NUMQUEUES) |
117 | queueList equ queues + (2 * NUMQUEUES) |
258 | last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES ) |
118 | last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES ) |
259 | 119 | ||
260 | ;resendQ equ queueList + ( 2 * NUMQUEUEENTRIES ) |
120 | ;resendQ equ queueList + ( 2 * NUMQUEUEENTRIES ) |
261 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
121 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
262 | ; equ resendBuffer + ( IPBUFFSIZE * NUMRESENDENTRIES ) |
122 | ; equ resendBuffer + ( IPBUFFSIZE * NUMRESENDENTRIES ) |
263 | 123 | ||
264 | 124 | ||
265 | 125 | ||
266 | resendQ equ 0x770000 |
126 | resendQ equ 0x770000 |
267 | resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
127 | resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
268 | 128 | ||
- | 129 | ||
- | 130 | ; simple macro for memory set operation |
|
- | 131 | macro _memset_dw adr,value,amount |
|
- | 132 | { |
|
- | 133 | mov edi, adr |
|
- | 134 | mov ecx, amount |
|
- | 135 | if value = 0 |
|
- | 136 | xor eax, eax |
|
- | 137 | else |
|
- | 138 | mov eax, value |
|
- | 139 | end if |
|
- | 140 | cld |
|
- | 141 | rep stosd |
|
- | 142 | } |
|
- | 143 | ||
- | 144 | ||
- | 145 | ; Below, the main network layer source code is included |
|
- | 146 | ; |
|
- | 147 | include "queue.inc" |
|
- | 148 | include "eth_drv/ethernet.inc" |
|
- | 149 | include "ip.inc" |
|
- | 150 | include "icmp.inc" |
|
- | 151 | include "tcp.inc" |
|
- | 152 | include "udp.inc" |
|
- | 153 | include "socket.inc" |
|
269 | 154 | ||
270 | ;*************************************************************************** |
155 | ;*************************************************************************** |
271 | ; Function |
156 | ; Function |
272 | ; stack_init |
157 | ; stack_init |
273 | ; |
158 | ; |
274 | ; Description |
159 | ; Description |
275 | ; Clear all allocated memory to zero. This ensures that |
160 | ; Clear all allocated memory to zero. This ensures that |
276 | ; on startup, the stack is inactive, and consumes no resources |
161 | ; on startup, the stack is inactive, and consumes no resources |
277 | ; 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 |
278 | ; in set_variables |
163 | ; in set_variables |
279 | ; |
164 | ; |
280 | ;*************************************************************************** |
165 | ;*************************************************************************** |
281 | stack_init: |
- | |
282 | xor eax,eax |
- | |
283 | mov edi,stack_data_start |
- | |
284 | mov ecx,0x20000 / 4 ; Assume that we have 128KB of data |
- | |
285 | cld |
- | |
286 | rep stosd |
- | |
287 | - | ||
288 | ; Initialise TCP resend queue data structures |
- | |
289 | mov eax, 0xFFFFFFFF |
- | |
290 | mov edi, resendQ |
- | |
291 | mov ecx, NUMRESENDENTRIES ; 1 dword per entry |
- | |
292 | cld |
- | |
293 | rep stosd |
- | |
- | 166 | ||
- | 167 | stack_init: |
|
- | 168 | ; Init two address spaces with default values |
|
- | 169 | _memset_dw stack_data_start, 0, 0x20000/4 |
|
294 | - | ||
295 | - | ||
296 | mov eax, 0xFFFFFFFF |
- | |
297 | mov [rx_buff_ptr], eax |
- | |
298 | mov [tx_buff_ptr], eax |
- | |
299 | - | ||
300 | ; Put in some defaults : slip, 0x3f8, 4, ip=192.168.1.22 |
- | |
301 | ; Saves me entering them each boot up when debugging |
- | |
302 | mov eax, 0x03f80401 |
- | |
303 | mov [stack_config], eax |
170 | _memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES |
304 | mov eax, 0xc801a8c0 |
- | |
305 | mov [stack_ip], eax |
171 | |
306 | 172 | ; Queries initialization |
|
307 | call queueInit |
173 | call queueInit |
308 | 174 | ||
309 | ; The following block sets up the 1s timer |
175 | ; The following block sets up the 1s timer |
310 | mov al,0x0 |
176 | mov al, 0x0 |
311 | out 0x70,al |
177 | out 0x70, al |
312 | in al,0x71 |
178 | in al, 0x71 |
313 | mov [last_1sTick], al |
179 | mov [last_1sTick], al |
314 | - | ||
315 | ret |
180 | ret |
316 | 181 | ||
317 | 182 | ||
318 | 183 | ||
319 | ;*************************************************************************** |
184 | ;*************************************************************************** |
320 | ; Function |
185 | ; Function |
321 | ; stack_handler |
186 | ; stack_handler |
322 | ; |
187 | ; |
323 | ; Description |
188 | ; Description |
324 | ; The kernel loop routine for the stack |
189 | ; The kernel loop routine for the stack |
325 | ; This is a kernel function, called in the main loop |
190 | ; This is a kernel function, called in the main loop |
326 | ; |
191 | ; |
327 | ;*************************************************************************** |
192 | ;*************************************************************************** |
328 | stack_handler: |
193 | stack_handler: |
329 | 194 | ||
330 | call ethernet_driver |
195 | call ethernet_driver |
331 | call ip_rx |
196 | call ip_rx |
332 | 197 | ||
333 | 198 | ||
334 | ; Test for 10ms tick, call tcp timer |
199 | ; Test for 10ms tick, call tcp timer |
335 | mov eax, [timer_ticks] ;[0xfdf0] |
200 | mov eax, [timer_ticks] ;[0xfdf0] |
336 | cmp eax, [last_1hsTick] |
201 | cmp eax, [last_1hsTick] |
337 | je sh_001 |
202 | je sh_001 |
338 | 203 | ||
339 | mov [last_1hsTick], eax |
204 | mov [last_1hsTick], eax |
340 | call tcp_tx_handler |
205 | call tcp_tx_handler |
341 | 206 | ||
342 | sh_001: |
207 | sh_001: |
343 | 208 | ||
344 | ; Test for 1 second event, call 1s timer functions |
209 | ; Test for 1 second event, call 1s timer functions |
345 | mov al,0x0 ;second |
210 | mov al, 0x0 ;second |
346 | out 0x70,al |
211 | out 0x70, al |
347 | in al,0x71 |
212 | in al, 0x71 |
348 | cmp al, [last_1sTick] |
213 | cmp al, [last_1sTick] |
349 | je sh_exit |
214 | je sh_exit |
350 | 215 | ||
351 | mov [last_1sTick], al |
216 | mov [last_1sTick], al |
352 | 217 | ||
353 | call arp_timer |
218 | stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0 |
354 | call tcp_tcb_handler |
219 | call tcp_tcb_handler |
355 | 220 | ||
356 | sh_exit: |
221 | sh_exit: |
357 | ret |
222 | ret |
- | 223 | ||
- | 224 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
- | 225 | ;; Checksum [by Johnny_B] |
|
- | 226 | ;; IN: |
|
- | 227 | ;; buf_ptr=POINTER to buffer |
|
- | 228 | ;; buf_size=SIZE of buffer |
|
- | 229 | ;; OUT: |
|
- | 230 | ;; AX=16-bit checksum |
|
- | 231 | ;; Saves all used registers |
|
- | 232 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
- | 233 | proc checksum_jb stdcall uses ebx esi ecx,\ |
|
- | 234 | buf_ptr:DWORD, buf_size:DWORD |
|
- | 235 | ||
- | 236 | xor eax, eax |
|
- | 237 | xor ebx, ebx ;accumulator |
|
- | 238 | mov esi, dword[buf_ptr] |
|
- | 239 | mov ecx, dword[buf_size] |
|
- | 240 | shr ecx, 1 ; ecx=ecx/2 |
|
- | 241 | jnc @f ; if CF==0 then size is even number |
|
- | 242 | mov bh, byte[esi + ecx*2] |
|
- | 243 | @@: |
|
- | 244 | cld |
|
- | 245 | ||
- | 246 | .loop: |
|
- | 247 | lodsw ;eax=word[esi],esi=esi+2 |
|
358 | - | ||
359 | - | ||
360 | - | ||
361 | - | ||
362 | ;*************************************************************************** |
- | |
363 | ; Function |
- | |
364 | ; is_localport_unused |
- | |
365 | ; |
- | |
366 | ; Description |
- | |
367 | ; scans through all the active sockets , looking to see if the |
- | |
368 | ; port number specified in bx is in use as a localport number. |
- | |
369 | ; This is useful when you want a to generate a unique local port |
- | |
370 | ; number. |
- | |
371 | ; On return, eax = 1 for free, 0 for in use |
248 | xchg ah,al ;cause must be a net byte-order |
372 | ; |
249 | add ebx, eax |
373 | ;*************************************************************************** |
250 | loop .loop |
374 | is_localport_unused: |
- | |
375 | mov al, bh |
- | |
376 | mov ah, bl |
- | |
377 | mov bx, ax |
- | |
378 | - | ||
379 | mov edx, SOCKETBUFFSIZE * NUM_SOCKETS |
- | |
380 | mov ecx, NUM_SOCKETS |
- | |
381 | mov eax, 0 ; Assume the return value is 'in use' |
- | |
382 | - | ||
383 | ilu1: |
- | |
384 | sub edx, SOCKETBUFFSIZE |
- | |
385 | cmp [edx + sockets + 12], bx |
- | |
386 | loopnz ilu1 ; Return back if the socket is occupied |
- | |
387 | - | ||
388 | jz ilu_exit |
- | |
389 | inc eax ; return port not in use |
- | |
390 | - | ||
391 | ilu_exit: |
- | |
392 | ret |
- | |
393 | - | ||
394 | - | ||
395 | - | ||
396 | ;*************************************************************************** |
- | |
397 | ; Function |
- | |
398 | ; get_free_socket |
- | |
399 | ; |
- | |
400 | ; Description |
- | |
401 | ; |
- | |
402 | ;*************************************************************************** |
- | |
403 | get_free_socket: |
- | |
404 | push ecx |
- | |
405 | mov eax, SOCKETBUFFSIZE * NUM_SOCKETS |
- | |
406 | mov ecx, NUM_SOCKETS |
- | |
407 | - | ||
408 | gfs1: |
- | |
409 | sub eax, SOCKETBUFFSIZE |
251 | |
410 | cmp [eax + sockets], dword SOCK_EMPTY |
- | |
411 | loopnz gfs1 ; Return back if the socket is occupied |
- | |
412 | mov eax, ecx |
- | |
413 | pop ecx |
252 | mov eax, ebx |
414 | jz gfs_exit |
- | |
415 | mov eax, 0xFFFFFFFF |
253 | shr eax, 16 |
416 | 254 | add ax, bx |
|
417 | gfs_exit: |
255 | not ax |
418 | ret |
256 | |
419 | 257 | ret |
|
420 | 258 | endp |
|
421 | 259 | ||
422 | ;*************************************************************************** |
260 | ;*************************************************************************** |
423 | ; Function |
261 | ; Function |
424 | ; checksum |
262 | ; checksum |
425 | ; |
263 | ; |
426 | ; Description |
264 | ; Description |
427 | ; checkAdd1,checkAdd2, checkSize1, checkSize2, checkResult |
265 | ; checkAdd1,checkAdd2, checkSize1, checkSize2, checkResult |
428 | ; Dont break anything; Most registers are used by the caller |
266 | ; Dont break anything; Most registers are used by the caller |
429 | ; 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 |
430 | ; Internetworking with TCP/IP Volume II by D.E. Comer |
268 | ; Internetworking with TCP/IP Volume II by D.E. Comer |
431 | ; |
269 | ; |
432 | ;*************************************************************************** |
270 | ;*************************************************************************** |
- | 271 | ||
- | 272 | ||
433 | checksum: |
273 | checksum: |
434 | pusha |
274 | pusha |
435 | - | ||
- | 275 | mov eax, [checkAdd1] |
|
436 | xor edx, edx ; edx is the accumulative checksum |
276 | xor edx, edx ; edx is the accumulative checksum |
437 | xor ebx, ebx |
277 | xor ebx, ebx |
438 | mov cx, [checkSize1] |
278 | mov cx, [checkSize1] |
439 | shr cx, 1 |
279 | shr cx, 1 |
440 | jz cs1_1 |
280 | jz cs1_1 |
441 | - | ||
442 | mov eax, [checkAdd1] |
- | |
443 | 281 | ||
444 | cs1: |
282 | cs1: |
445 | mov bh, [eax] |
283 | mov bh, [eax] |
446 | mov bl, [eax + 1] |
284 | mov bl, [eax + 1] |
447 | 285 | ||
448 | add eax, 2 |
286 | add eax, 2 |
449 | add edx, ebx |
287 | add edx, ebx |
450 | 288 | ||
451 | loopw cs1 |
289 | loopw cs1 |
452 | 290 | ||
453 | cs1_1: |
291 | cs1_1: |
454 | and word [checkSize1], 0x01 |
292 | and word [checkSize1], 0x01 |
455 | jz cs_test2 |
293 | jz cs_test2 |
456 | 294 | ||
457 | mov bh, [eax] |
295 | mov bh, [eax] |
458 | xor bl, bl |
296 | xor bl, bl |
459 | 297 | ||
460 | add edx, ebx |
298 | add edx, ebx |
461 | 299 | ||
462 | cs_test2: |
300 | cs_test2: |
463 | mov cx, [checkSize2] |
301 | mov cx, [checkSize2] |
464 | cmp cx, 0 |
302 | cmp cx, 0 |
465 | jz cs_exit ; Finished if no 2nd buffer |
303 | jz cs_exit ; Finished if no 2nd buffer |
- | 304 | ||
- | 305 | mov eax, [checkAdd2] |
|
466 | 306 | ||
467 | shr cx, 1 |
307 | shr cx, 1 |
468 | jz cs2_1 |
308 | jz cs2_1 |
469 | - | ||
470 | mov eax, [checkAdd2] |
- | |
471 | 309 | ||
472 | cs2: |
310 | cs2: |
473 | mov bh, [eax] |
311 | mov bh, [eax] |
474 | mov bl, [eax + 1] |
312 | mov bl, [eax + 1] |
475 | 313 | ||
476 | add eax, 2 |
314 | add eax, 2 |
477 | add edx, ebx |
315 | add edx, ebx |
478 | 316 | ||
479 | loopw cs2 |
317 | loopw cs2 |
480 | 318 | ||
481 | cs2_1: |
319 | cs2_1: |
482 | and word [checkSize2], 0x01 |
320 | and word [checkSize2], 0x01 |
483 | jz cs_exit |
321 | jz cs_exit |
484 | 322 | ||
485 | mov bh, [eax] |
323 | mov bh, [eax] |
486 | xor bl, bl |
324 | xor bl, bl |
487 | 325 | ||
488 | add edx, ebx |
326 | add edx, ebx |
489 | 327 | ||
490 | cs_exit: |
328 | cs_exit: |
491 | mov ebx, edx |
329 | mov ebx, edx |
492 | 330 | ||
493 | shr ebx, 16 |
331 | shr ebx, 16 |
494 | and edx, 0xffff |
332 | and edx, 0xffff |
495 | add edx, ebx |
333 | add edx, ebx |
496 | mov eax, edx |
334 | mov eax, edx |
497 | shr eax, 16 |
335 | shr eax, 16 |
498 | add edx, eax |
336 | add edx, eax |
499 | not dx |
337 | not dx |
500 | 338 | ||
501 | mov [checkResult], dx |
339 | mov [checkResult], dx |
502 | popa |
340 | popa |
503 | ret |
341 | ret |
504 | 342 | ||
505 | 343 | ||
506 | 344 | ||
507 | 345 | ||
508 | ;*************************************************************************** |
346 | ;*************************************************************************** |
509 | ; Function |
347 | ; Function |
510 | ; app_stack_handler |
348 | ; app_stack_handler |
511 | ; |
349 | ; |
512 | ; Description |
350 | ; Description |
513 | ; This is an application service, called by int 0x40 fn 52 |
351 | ; This is an application service, called by int 0x40, function 52 |
514 | ; It provides application access to the network interface layer |
352 | ; It provides application access to the network interface layer |
515 | ; |
353 | ; |
516 | ;*************************************************************************** |
354 | ;*************************************************************************** |
517 | app_stack_handler: |
355 | app_stack_handler: |
518 | cmp eax, 0 |
356 | cmp eax, 0 |
519 | jnz not0 |
357 | jnz not0 |
520 | ; Read the configuartion word |
358 | ; Read the configuration word |
521 | mov eax, [stack_config] |
359 | mov eax, [stack_config] |
522 | ret |
360 | ret |
523 | 361 | ||
524 | not0: |
362 | not0: |
525 | cmp eax, 1 |
363 | cmp eax, 1 |
526 | jnz not1 |
364 | jnz not1 |
527 | ; read the IP address |
365 | ; read the IP address |
528 | 366 | ||
529 | mov eax, [stack_ip] |
367 | mov eax, [stack_ip] |
530 | ret |
368 | ret |
531 | 369 | ||
532 | not1: |
370 | not1: |
533 | cmp eax, 2 |
371 | cmp eax, 2 |
534 | jnz not2 |
372 | jnz not2 |
535 | 373 | ||
536 | ; write the configuration word |
374 | ; write the configuration word |
537 | mov [stack_config], ebx |
375 | mov [stack_config], ebx |
538 | 376 | ||
539 | ; |
377 | ; |
540 | ; 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 |
541 | ; the packet buffer |
379 | ; the packet buffer |
542 | ; If all successfull, enable the card. |
380 | ; If all successfull, enable the card. |
543 | ; If ethernet now disabled, set it as disabled. Should really |
381 | ; If ethernet now disabled, set it as disabled. Should really |
544 | ; empty the tcpip data area too. |
382 | ; empty the tcpip data area too. |
545 | 383 | ||
546 | ; ethernet interface is '3' in ls 7 bits |
384 | ; ethernet interface is '3' in ls 7 bits |
547 | and bl, 0x7f |
385 | and bl, 0x7f |
548 | cmp bl, 3 |
386 | cmp bl, 3 |
549 | 387 | ||
550 | je ash_eth_enable |
388 | je ash_eth_enable |
551 | ; 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 |
552 | mov [ethernet_active], byte 0 |
390 | mov [ethernet_active], byte 0 |
553 | 391 | ||
554 | ret |
392 | ret |
555 | 393 | ||
556 | ash_eth_enable: |
394 | ash_eth_enable: |
557 | ; 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 |
558 | ; if found |
396 | ; if found |
559 | call eth_probe |
397 | call eth_probe |
560 | cmp eax, 0 |
398 | cmp eax, 0 |
561 | je ash_eth_done ; Abort if no hardware found |
399 | je ash_eth_done ; Abort if no hardware found |
562 | 400 | ||
563 | mov [ethernet_active], byte 1 |
401 | mov [ethernet_active], byte 1 |
564 | 402 | ||
565 | ash_eth_done: |
403 | ash_eth_done: |
566 | ret |
404 | ret |
567 | 405 | ||
568 | not2: |
406 | not2: |
569 | cmp eax, 3 |
407 | cmp eax, 3 |
570 | jnz not3 |
408 | jnz not3 |
571 | ; write the IP Address |
409 | ; write the IP Address |
572 | mov [stack_ip], ebx |
410 | mov [stack_ip], ebx |
573 | ret |
411 | ret |
574 | - | ||
575 | not3: |
- | |
576 | cmp eax, 4 |
- | |
577 | jnz not4 |
- | |
578 | ; Enabled the slip driver on the comm port |
412 | |
579 | ; slip removed |
- | |
580 | ret |
- | |
581 | - | ||
582 | not4: |
- | |
583 | cmp eax, 5 |
- | |
584 | jnz not5 |
- | |
585 | ; Disable the slip driver on the comm port |
- | |
586 | ; slip removed |
413 | ;old functions was deleted |
587 | 414 | ||
588 | not5: |
415 | not3: |
589 | cmp eax, 6 |
416 | cmp eax, 6 |
590 | jnz not6 |
417 | jnz not6 |
591 | 418 | ||
592 | ; Insert an IP packet into the stacks received packet queue |
419 | ; Insert an IP packet into the stacks received packet queue |
593 | call stack_insert_packet |
420 | call stack_insert_packet |
594 | ret |
421 | ret |
595 | 422 | ||
596 | not6: |
423 | not6: |
597 | cmp eax, 7 |
424 | cmp eax, 7 |
598 | jnz not7 |
425 | jnz not7 |
599 | 426 | ||
600 | ; Test for any packets queued for transmission over the network |
427 | ; Test for any packets queued for transmission over the network |
601 | 428 | ||
602 | not7: |
429 | not7: |
603 | cmp eax, 8 |
430 | cmp eax, 8 |
604 | jnz not8 |
431 | jnz not8 |
605 | 432 | ||
606 | call stack_get_packet |
433 | call stack_get_packet |
607 | ; Extract a packet queued for transmission by the network |
434 | ; Extract a packet queued for transmission by the network |
608 | ret |
435 | ret |
609 | 436 | ||
610 | not8: |
437 | not8: |
611 | cmp eax, 9 |
438 | cmp eax, 9 |
612 | jnz not9 |
439 | jnz not9 |
613 | 440 | ||
614 | ; read the gateway IP address |
441 | ; read the gateway IP address |
615 | 442 | ||
616 | mov eax, [gateway_ip] |
443 | mov eax, [gateway_ip] |
617 | ret |
444 | ret |
618 | 445 | ||
619 | not9: |
446 | not9: |
620 | cmp eax, 10 |
447 | cmp eax, 10 |
621 | jnz not10 |
448 | jnz not10 |
622 | 449 | ||
623 | ; read the subnet mask |
450 | ; read the subnet mask |
624 | 451 | ||
625 | mov eax, [subnet_mask] |
452 | mov eax, [subnet_mask] |
626 | ret |
453 | ret |
627 | 454 | ||
628 | not10: |
455 | not10: |
629 | cmp eax, 11 |
456 | cmp eax, 11 |
630 | jnz not11 |
457 | jnz not11 |
631 | 458 | ||
632 | ; write the gateway IP Address |
459 | ; write the gateway IP Address |
633 | mov [gateway_ip], ebx |
460 | mov [gateway_ip], ebx |
634 | 461 | ||
635 | ret |
462 | ret |
636 | 463 | ||
637 | not11: |
464 | not11: |
638 | cmp eax, 12 |
465 | cmp eax, 12 |
639 | jnz not12 |
466 | jnz not12 |
640 | 467 | ||
641 | ; write the subnet mask |
468 | ; write the subnet mask |
642 | mov [subnet_mask], ebx |
469 | mov [subnet_mask], ebx |
643 | 470 | ||
644 | 471 | ||
645 | not12: |
472 | not12: |
646 | cmp eax, 13 |
473 | cmp eax, 13 |
647 | jnz not13 |
474 | jnz not13 |
648 | 475 | ||
649 | ; read the dns |
476 | ; read the dns |
650 | 477 | ||
651 | mov eax, [dns_ip] |
478 | mov eax, [dns_ip] |
652 | ret |
479 | ret |
653 | 480 | ||
654 | not13: |
481 | not13: |
655 | cmp eax, 14 |
482 | cmp eax, 14 |
656 | jnz stack_driver_end |
483 | jnz not14 |
657 | 484 | ||
658 | ; write the dns IP Address |
485 | ; write the dns IP Address |
659 | mov [dns_ip], ebx |
486 | mov [dns_ip], ebx |
660 | 487 | ||
661 | ret |
488 | ret |
- | 489 | ||
- | 490 | ; |
|
- | 491 | not14: |
|
- | 492 | cmp eax, 15 |
|
- | 493 | jnz not15 |
|
- | 494 | ||
- | 495 | ; in ebx we need 4 to read the last 2 bytes |
|
- | 496 | cmp ebx, dword 4 |
|
- | 497 | je read |
|
- | 498 | ||
- | 499 | ; or we need 0 to read the first 4 bytes |
|
- | 500 | cmp ebx, dword 0 |
|
- | 501 | jnz param_error |
|
- | 502 | ||
- | 503 | ; read MAC, returned (in mirrored byte order) in eax |
|
- | 504 | read: |
|
- | 505 | mov eax, [node_addr + ebx] |
|
- | 506 | jmp @f |
|
- | 507 | ||
- | 508 | param_error: |
|
- | 509 | mov eax, -1 ; params not accepted |
|
- | 510 | @@: |
|
- | 511 | ret |
|
- | 512 | ||
- | 513 | ||
- | 514 | ; 0 -> arp_probe |
|
- | 515 | ; 1 -> arp_announce |
|
- | 516 | ; 2 -> arp_responce (not supported yet) |
|
- | 517 | ||
- | 518 | not15: ; ARP stuff |
|
- | 519 | cmp eax, 16 |
|
- | 520 | jnz not16 |
|
- | 521 | ||
- | 522 | cmp ebx, 0 |
|
- | 523 | je a_probe |
|
- | 524 | ||
- | 525 | cmp ebx, 1 |
|
- | 526 | je a_ann ; arp announce |
|
- | 527 | ||
- | 528 | ; cmp ebx,2 |
|
- | 529 | ; jne a_resp ; arp response |
|
- | 530 | ||
- | 531 | jmp param15_error |
|
- | 532 | ||
- | 533 | ||
- | 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 |
|
- | 536 | ; edx: target IP |
|
- | 537 | a_probe: |
|
- | 538 | push dword [stack_ip] |
|
- | 539 | ||
- | 540 | mov edx, [stack_ip] |
|
- | 541 | mov [stack_ip], dword 0 |
|
- | 542 | mov esi, ecx ; pointer to target MAC address |
|
- | 543 | call arp_request |
|
- | 544 | ||
- | 545 | pop dword [stack_ip] |
|
- | 546 | jmp @f |
|
- | 547 | ||
- | 548 | ; arp announce, sender IP must be set to target IP |
|
- | 549 | ; ecx: pointer to target MAC |
|
- | 550 | a_ann: |
|
- | 551 | mov edx, [stack_ip] |
|
- | 552 | mov esi, ecx ; pointer to target MAC address |
|
- | 553 | call arp_request |
|
- | 554 | jmp @f |
|
- | 555 | ||
- | 556 | param15_error: |
|
- | 557 | mov eax, -1 |
|
- | 558 | ||
- | 559 | @@: |
|
- | 560 | ret |
|
- | 561 | ; |
|
- | 562 | ; modified by [smb] |
|
- | 563 | ||
- | 564 | ; |
|
- | 565 | ; ARPTable manager interface |
|
- | 566 | not16: |
|
- | 567 | cmp eax, 17 |
|
- | 568 | jnz stack_driver_end |
|
- | 569 | ||
- | 570 | ;see "proc arp_table_manager" for more details |
|
- | 571 | stdcall arp_table_manager,ebx,ecx,edx ;Opcode,Index,Extra |
|
- | 572 | ||
- | 573 | ret |
|
- | 574 | ; |
|
662 | 575 | ||
663 | stack_driver_end: |
576 | stack_driver_end: |
664 | ret |
577 | ret |
665 | 578 | ||
666 | 579 | ||
667 | 580 | ||
668 | ;*************************************************************************** |
581 | ;*************************************************************************** |
669 | ; Function |
582 | ; Function |
670 | ; app_socket_handler |
583 | ; app_socket_handler |
671 | ; |
584 | ; |
672 | ; Description |
585 | ; Description |
673 | ; This is an application service, called by int 0x40 |
586 | ; This is an application service, called by int 0x40, function 53 |
674 | ; It provides application access to stack socket services |
587 | ; It provides application access to stack socket services |
675 | ; such as opening sockets |
588 | ; such as opening sockets |
676 | ; |
589 | ; |
677 | ;*************************************************************************** |
590 | ;*************************************************************************** |
678 | app_socket_handler: |
591 | app_socket_handler: |
679 | cmp eax, 0 |
592 | cmp eax, 0 |
680 | jnz nots0 |
593 | jnz nots0 |
681 | 594 | ||
682 | call socket_open |
595 | call socket_open |
683 | ret |
596 | ret |
684 | 597 | ||
685 | nots0: |
598 | nots0: |
686 | cmp eax, 1 |
599 | cmp eax, 1 |
687 | jnz nots1 |
600 | jnz nots1 |
688 | 601 | ||
689 | call socket_close |
602 | call socket_close |
690 | ret |
603 | ret |
691 | 604 | ||
692 | nots1: |
605 | nots1: |
693 | cmp eax, 2 |
606 | cmp eax, 2 |
694 | jnz nots2 |
607 | jnz nots2 |
695 | 608 | ||
696 | call socket_poll |
609 | call socket_poll |
697 | ret |
610 | ret |
698 | 611 | ||
699 | nots2: |
612 | nots2: |
700 | cmp eax, 3 |
613 | cmp eax, 3 |
701 | jnz nots3 |
614 | jnz nots3 |
702 | 615 | ||
703 | call socket_read |
616 | call socket_read |
704 | ret |
617 | ret |
705 | 618 | ||
706 | nots3: |
619 | nots3: |
707 | cmp eax, 4 |
620 | cmp eax, 4 |
708 | jnz nots4 |
621 | jnz nots4 |
709 | 622 | ||
710 | call socket_write |
623 | call socket_write |
711 | ret |
624 | ret |
712 | 625 | ||
713 | nots4: |
626 | nots4: |
714 | cmp eax, 5 |
627 | cmp eax, 5 |
715 | jnz nots5 |
628 | jnz nots5 |
716 | 629 | ||
717 | call socket_open_tcp |
630 | call socket_open_tcp |
718 | ret |
631 | ret |
719 | 632 | ||
720 | nots5: |
633 | nots5: |
721 | cmp eax, 6 |
634 | cmp eax, 6 |
722 | jnz nots6 |
635 | jnz nots6 |
723 | 636 | ||
724 | call socket_status |
637 | call socket_status |
725 | ret |
638 | ret |
726 | 639 | ||
727 | nots6: |
640 | nots6: |
728 | cmp eax, 7 |
641 | cmp eax, 7 |
729 | jnz nots7 |
642 | jnz nots7 |
730 | 643 | ||
731 | call socket_write_tcp |
644 | call socket_write_tcp |
732 | ret |
645 | ret |
733 | 646 | ||
734 | nots7: |
647 | nots7: |
735 | cmp eax, 8 |
648 | cmp eax, 8 |
736 | jnz nots8 |
649 | jnz nots8 |
737 | 650 | ||
738 | call socket_close_tcp |
651 | call socket_close_tcp |
739 | ret |
652 | ret |
740 | 653 | ||
741 | nots8: |
654 | nots8: |
742 | cmp eax, 9 |
655 | cmp eax, 9 |
743 | jnz nots9 |
656 | jnz nots9 |
744 | 657 | ||
745 | call is_localport_unused |
658 | call is_localport_unused |
746 | ret |
659 | ret |
747 | 660 | ||
748 | nots9: |
661 | nots9: |
- | 662 | cmp eax, 10 |
|
- | 663 | jnz nots10 |
|
- | 664 | ||
- | 665 | mov eax,dword[drvr_cable] |
|
- | 666 | test eax,eax |
|
- | 667 | jnz @f ; if function is not implented, return -1 |
|
- | 668 | mov al,-1 |
|
- | 669 | ret |
|
- | 670 | ||
- | 671 | @@: |
|
- | 672 | call dword[drvr_cable] |
|
- | 673 | ret |
|
- | 674 | ||
- | 675 | ||
- | 676 | nots10: |
|
- | 677 | cmp eax, 11 |
|
- | 678 | jnz nots11 |
|
- | 679 | ||
- | 680 | call socket_read_packet |
|
- | 681 | ret |
|
- | 682 | ||
- | 683 | nots11: |
|
749 | cmp eax, 254 |
684 | cmp eax, 254 |
750 | jnz notdump |
685 | jnz notdump |
751 | 686 | ||
752 | ret |
687 | ret |
753 | 688 | ||
754 | notdump: |
689 | notdump: |
755 | cmp eax, 255 |
690 | cmp eax, 255 |
756 | jnz notsdebug |
691 | jnz notsdebug |
757 | 692 | ||
758 | ; This sub function allows access to debugging information on the stack |
693 | ; This sub function allows access to debugging information on the stack |
759 | ; ebx holds the request: |
694 | ; ebx holds the request: |
760 | ; 100 : return length of empty queue |
695 | ; 100 : return length of empty queue |
761 | ; 101 : return length of IPOUT QUEUE |
696 | ; 101 : return length of IPOUT QUEUE |
762 | ; 102 : return length of IPIN QUEUE |
697 | ; 102 : return length of IPIN QUEUE |
763 | ; 103 : return length of NET1OUT QUEUE |
698 | ; 103 : return length of NET1OUT QUEUE |
764 | ; 200 : return # of ARP entries |
699 | ; 200 : return # of ARP entries |
765 | ; 201 : return size of ARP table ( max # entries ) |
700 | ; 201 : return size of ARP table ( max # entries ) |
766 | ; 202 : select ARP table entry # |
701 | ; 202 : select ARP table entry # |
767 | ; 203 : return IP of selected table entry |
702 | ; 203 : return IP of selected table entry |
768 | ; 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 |
769 | ; 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 |
770 | ; 206 : return status word of selected table entry |
705 | ; 206 : return status word of selected table entry |
771 | ; 207 : return Time to live of selected table entry |
706 | ; 207 : return Time to live of selected table entry |
772 | 707 | ||
773 | 708 | ||
774 | ; 2 : return number of IP packets received |
709 | ; 2 : return number of IP packets received |
775 | ; 3 : return number of packets transmitted |
710 | ; 3 : return number of packets transmitted |
776 | ; 4 : return number of received packets dumped |
711 | ; 4 : return number of received packets dumped |
777 | ; 5 : return number of arp packets received |
712 | ; 5 : return number of arp packets received |
778 | ; 6 : return status of packet driver |
713 | ; 6 : return status of packet driver |
779 | ; ( 0 == not active, FFFFFFFF = successful ) |
714 | ; ( 0 == not active, FFFFFFFF = successful ) |
780 | 715 | ||
781 | call stack_internal_status |
716 | call stack_internal_status |
782 | ret |
717 | ret |
783 | 718 | ||
784 | notsdebug: |
719 | notsdebug: |
785 | ; Invalid Option |
720 | ; Invalid Option |
786 | ret |
721 | ret |
787 | 722 | ||
788 | 723 | ||
789 | uglobal |
724 | uglobal |
790 | ARPTmp: |
725 | ARPTmp: |
791 | times 14 db 0 |
726 | times 14 db 0 |
792 | endg |
727 | endg |
793 | 728 | ||
794 | ;*************************************************************************** |
729 | ;*************************************************************************** |
795 | ; Function |
730 | ; Function |
796 | ; stack_internal_status |
731 | ; stack_internal_status |
797 | ; |
732 | ; |
798 | ; Description |
733 | ; Description |
799 | ; Returns information about the internal status of the stack |
734 | ; Returns information about the internal status of the stack |
800 | ; This is only useful for debugging |
735 | ; This is only useful for debugging |
801 | ; It works with the ethernet driver |
736 | ; It works with the ethernet driver |
802 | ; sub function in ebx |
737 | ; sub function in ebx |
803 | ; return requested data in eax |
738 | ; return requested data in eax |
804 | ; |
739 | ; |
805 | ;*************************************************************************** |
740 | ;*************************************************************************** |
806 | stack_internal_status: |
741 | stack_internal_status: |
807 | cmp ebx, 100 |
742 | cmp ebx, 100 |
808 | jnz notsis100 |
743 | jnz notsis100 |
809 | 744 | ||
810 | ; 100 : return length of EMPTY QUEUE |
745 | ; 100 : return length of EMPTY QUEUE |
811 | mov ebx, EMPTY_QUEUE |
746 | mov ebx, EMPTY_QUEUE |
812 | call queueSize |
747 | call queueSize |
813 | ret |
748 | ret |
814 | 749 | ||
815 | notsis100: |
750 | notsis100: |
816 | cmp ebx, 101 |
751 | cmp ebx, 101 |
817 | jnz notsis101 |
752 | jnz notsis101 |
818 | 753 | ||
819 | ; 101 : return length of IPOUT QUEUE |
754 | ; 101 : return length of IPOUT QUEUE |
820 | mov ebx, IPOUT_QUEUE |
755 | mov ebx, IPOUT_QUEUE |
821 | call queueSize |
756 | call queueSize |
822 | ret |
757 | ret |
823 | 758 | ||
824 | notsis101: |
759 | notsis101: |
825 | cmp ebx, 102 |
760 | cmp ebx, 102 |
826 | jnz notsis102 |
761 | jnz notsis102 |
827 | 762 | ||
828 | ; 102 : return length of IPIN QUEUE |
763 | ; 102 : return length of IPIN QUEUE |
829 | mov ebx, IPIN_QUEUE |
764 | mov ebx, IPIN_QUEUE |
830 | call queueSize |
765 | call queueSize |
831 | ret |
766 | ret |
832 | 767 | ||
833 | notsis102: |
768 | notsis102: |
834 | cmp ebx, 103 |
769 | cmp ebx, 103 |
835 | jnz notsis103 |
770 | jnz notsis103 |
836 | 771 | ||
837 | ; 103 : return length of NET1OUT QUEUE |
772 | ; 103 : return length of NET1OUT QUEUE |
838 | mov ebx, NET1OUT_QUEUE |
773 | mov ebx, NET1OUT_QUEUE |
839 | call queueSize |
774 | call queueSize |
840 | ret |
775 | ret |
841 | 776 | ||
842 | notsis103: |
777 | notsis103: |
843 | cmp ebx, 200 |
778 | cmp ebx, 200 |
844 | jnz notsis200 |
779 | jnz notsis200 |
845 | 780 | ||
846 | ; 200 : return num entries in arp table |
781 | ; 200 : return num entries in arp table |
847 | movzx eax, byte [NumARP] |
782 | movzx eax, byte [NumARP] |
848 | ret |
783 | ret |
849 | 784 | ||
850 | notsis200: |
785 | notsis200: |
851 | cmp ebx, 201 |
786 | cmp ebx, 201 |
852 | jnz notsis201 |
787 | jnz notsis201 |
853 | 788 | ||
854 | ; 201 : return arp table size |
789 | ; 201 : return arp table size |
855 | mov eax, 20 ; ARP_TABLE_SIZE |
790 | mov eax, 20 ; ARP_TABLE_SIZE |
856 | ret |
791 | ret |
857 | 792 | ||
858 | notsis201: |
793 | notsis201: |
859 | cmp ebx, 202 |
794 | cmp ebx, 202 |
860 | jnz notsis202 |
795 | jnz notsis202 |
861 | 796 | ||
862 | ; 202 - read the requested table entry |
797 | ; 202 - read the requested table entry |
863 | ; into a temporary buffer |
798 | ; into a temporary buffer |
864 | ; ecx holds the entry number |
799 | ; ecx holds the entry number |
865 | 800 | ||
866 | mov eax, ecx |
801 | mov eax, ecx |
867 | mov ecx, 14 ; ARP_ENTRY_SIZE |
802 | mov ecx, 14 ; ARP_ENTRY_SIZE |
868 | mul ecx |
803 | mul ecx |
869 | 804 | ||
870 | mov ecx, [eax + ARPTable] |
805 | mov ecx, [eax + ARPTable] |
871 | mov [ARPTmp], ecx |
806 | mov [ARPTmp], ecx |
872 | mov ecx, [eax + ARPTable+4] |
807 | mov ecx, [eax + ARPTable+4] |
873 | mov [ARPTmp+4], ecx |
808 | mov [ARPTmp+4], ecx |
874 | mov ecx, [eax + ARPTable+8] |
809 | mov ecx, [eax + ARPTable+8] |
875 | mov [ARPTmp+8], ecx |
810 | mov [ARPTmp+8], ecx |
876 | mov cx, [eax + ARPTable+12] |
811 | mov cx, [eax + ARPTable+12] |
877 | mov [ARPTmp+12], cx |
812 | mov [ARPTmp+12], cx |
878 | ret |
813 | ret |
879 | 814 | ||
880 | notsis202: |
815 | notsis202: |
881 | cmp ebx, 203 |
816 | cmp ebx, 203 |
882 | jnz notsis203 |
817 | jnz notsis203 |
883 | 818 | ||
884 | ; 203 - return IP address |
819 | ; 203 - return IP address |
885 | mov eax, [ARPTmp] |
820 | mov eax, [ARPTmp] |
886 | ret |
821 | ret |
887 | 822 | ||
888 | notsis203: |
823 | notsis203: |
889 | cmp ebx, 204 |
824 | cmp ebx, 204 |
890 | jnz notsis204 |
825 | jnz notsis204 |
891 | 826 | ||
892 | ; 204 - return MAC high dword |
827 | ; 204 - return MAC high dword |
893 | mov eax, [ARPTmp+4] |
828 | mov eax, [ARPTmp+4] |
894 | ret |
829 | ret |
895 | 830 | ||
896 | notsis204: |
831 | notsis204: |
897 | cmp ebx, 205 |
832 | cmp ebx, 205 |
898 | jnz notsis205 |
833 | jnz notsis205 |
899 | 834 | ||
900 | ; 205 - return MAC ls word |
835 | ; 205 - return MAC ls word |
901 | movzx eax, word [ARPTmp+8] |
836 | movzx eax, word [ARPTmp+8] |
902 | ret |
837 | ret |
903 | 838 | ||
904 | notsis205: |
839 | notsis205: |
905 | cmp ebx, 206 |
840 | cmp ebx, 206 |
906 | jnz notsis206 |
841 | jnz notsis206 |
907 | 842 | ||
908 | ; 206 - return status word |
843 | ; 206 - return status word |
909 | movzx eax, word [ARPTmp+10] |
844 | movzx eax, word [ARPTmp+10] |
910 | ret |
845 | ret |
911 | 846 | ||
912 | notsis206: |
847 | notsis206: |
913 | cmp ebx, 207 |
848 | cmp ebx, 207 |
914 | jnz notsis207 |
849 | jnz notsis207 |
915 | 850 | ||
916 | ; 207 - return ttl word |
851 | ; 207 - return ttl word |
917 | movzx eax, word [ARPTmp+12] |
852 | movzx eax, word [ARPTmp+12] |
918 | ret |
853 | ret |
919 | 854 | ||
920 | notsis207: |
855 | notsis207: |
921 | cmp ebx, 2 |
856 | cmp ebx, 2 |
922 | jnz notsis2 |
857 | jnz notsis2 |
923 | 858 | ||
924 | ; 2 : return number of IP packets received |
859 | ; 2 : return number of IP packets received |
925 | mov eax, [ip_rx_count] |
860 | mov eax, [ip_rx_count] |
926 | ret |
861 | ret |
927 | 862 | ||
928 | notsis2: |
863 | notsis2: |
929 | cmp ebx, 3 |
864 | cmp ebx, 3 |
930 | jnz notsis3 |
865 | jnz notsis3 |
931 | 866 | ||
932 | ; 3 : return number of packets transmitted |
867 | ; 3 : return number of packets transmitted |
933 | mov eax, [ip_tx_count] |
868 | mov eax, [ip_tx_count] |
934 | ret |
869 | ret |
935 | 870 | ||
936 | notsis3: |
871 | notsis3: |
937 | cmp ebx, 4 |
872 | cmp ebx, 4 |
938 | jnz notsis4 |
873 | jnz notsis4 |
939 | 874 | ||
940 | ; 4 : return number of received packets dumped |
875 | ; 4 : return number of received packets dumped |
941 | mov eax, [dumped_rx_count] |
876 | mov eax, [dumped_rx_count] |
942 | ret |
877 | ret |
943 | 878 | ||
944 | notsis4: |
879 | notsis4: |
945 | cmp ebx, 5 |
880 | cmp ebx, 5 |
946 | jnz notsis5 |
881 | jnz notsis5 |
947 | 882 | ||
948 | ; 5 : return number of arp packets received |
883 | ; 5 : return number of arp packets received |
949 | mov eax, [arp_rx_count] |
884 | mov eax, [arp_rx_count] |
950 | ret |
885 | ret |
951 | 886 | ||
952 | notsis5: |
887 | notsis5: |
953 | cmp ebx, 6 |
888 | cmp ebx, 6 |
954 | jnz notsis6 |
889 | jnz notsis6 |
955 | 890 | ||
956 | ; 6 : return status of packet driver |
891 | ; 6 : return status of packet driver |
957 | ; ( 0 == not active, FFFFFFFF = successful ) |
892 | ; ( 0 == not active, FFFFFFFF = successful ) |
958 | mov eax, [eth_status] |
893 | mov eax, [eth_status] |
959 | ret |
894 | ret |
960 | 895 | ||
961 | notsis6: |
896 | notsis6: |
962 | xor eax, eax |
897 | xor eax, eax |
963 | ret |
898 | ret |
964 | 899 | ||
965 | 900 | ||
966 | 901 | ||
967 | ;*************************************************************************** |
902 | ;*************************************************************************** |
968 | ; Function |
903 | ; Function |
969 | ; stack_get_packet |
904 | ; stack_get_packet |
970 | ; |
905 | ; |
971 | ; Description |
906 | ; Description |
972 | ; extracts an IP packet from the NET1 output queue |
907 | ; extracts an IP packet from the NET1 output queue |
973 | ; and sends the data to the calling process |
908 | ; and sends the data to the calling process |
974 | ; pointer to data in edx |
909 | ; pointer to data in edx |
975 | ; returns number of bytes read in eax |
910 | ; returns number of bytes read in eax |
976 | ; |
911 | ; |
977 | ;*************************************************************************** |
912 | ;*************************************************************************** |
978 | stack_get_packet: |
913 | stack_get_packet: |
979 | ; Look for a buffer to tx |
914 | ; Look for a buffer to tx |
980 | mov eax, NET1OUT_QUEUE |
915 | mov eax, NET1OUT_QUEUE |
981 | call dequeue |
916 | call dequeue |
982 | cmp ax, NO_BUFFER |
917 | cmp ax, NO_BUFFER |
983 | je sgp_non_exit ; Exit if no buffer available |
918 | je sgp_non_exit ; Exit if no buffer available |
984 | 919 | ||
985 | push eax ; Save buffer number for freeing at end |
920 | push eax ; Save buffer number for freeing at end |
986 | 921 | ||
987 | push edx |
922 | push edx |
988 | ; convert buffer pointer eax to the absolute address |
923 | ; convert buffer pointer eax to the absolute address |
989 | mov ecx, IPBUFFSIZE |
924 | mov ecx, IPBUFFSIZE |
990 | mul ecx |
925 | mul ecx |
991 | add eax, IPbuffs |
926 | add eax, IPbuffs |
992 | pop edx |
927 | pop edx |
993 | 928 | ||
994 | push eax ; save address of IP data |
929 | push eax ; save address of IP data |
995 | 930 | ||
996 | ; Get the address of the callers data |
931 | ; Get the address of the callers data |
997 | mov edi,[0x3010] |
932 | mov edi,[TASK_BASE] |
998 | add edi,TASKDATA.mem_start |
933 | add edi,TASKDATA.mem_start |
999 | add edx,[edi] |
934 | add edx,[edi] |
1000 | mov edi, edx |
935 | mov edi, edx |
1001 | 936 | ||
1002 | pop eax |
937 | pop eax |
1003 | 938 | ||
1004 | 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 |
1005 | mov esi, eax |
940 | mov esi, eax |
1006 | cld |
941 | cld |
1007 | rep movsb ; copy the data across |
942 | rep movsb ; copy the data across |
1008 | 943 | ||
1009 | ; And finally, return the buffer to the free queue |
944 | ; And finally, return the buffer to the free queue |
1010 | pop eax |
945 | pop eax |
1011 | call freeBuff |
946 | call freeBuff |
1012 | 947 | ||
1013 | mov eax, 1500 |
948 | mov eax, 1500 |
1014 | ret |
949 | ret |
1015 | 950 | ||
1016 | sgp_non_exit: |
951 | sgp_non_exit: |
1017 | xor eax, eax |
952 | xor eax, eax |
1018 | ret |
953 | ret |
1019 | 954 | ||
1020 | 955 | ||
1021 | 956 | ||
1022 | ;*************************************************************************** |
957 | ;*************************************************************************** |
1023 | ; Function |
958 | ; Function |
1024 | ; stack_insert_packet |
959 | ; stack_insert_packet |
1025 | ; |
960 | ; |
1026 | ; Description |
961 | ; Description |
1027 | ; writes an IP packet into the stacks receive queue |
962 | ; writes an IP packet into the stacks receive queue |
1028 | ; # of bytes to write in ecx |
963 | ; # of bytes to write in ecx |
1029 | ; pointer to data in edx |
964 | ; pointer to data in edx |
1030 | ; returns 0 in eax ok, -1 == failed |
965 | ; returns 0 in eax ok, -1 == failed |
1031 | ; |
966 | ; |
1032 | ;*************************************************************************** |
967 | ;*************************************************************************** |
1033 | stack_insert_packet: |
968 | stack_insert_packet: |
1034 | 969 | ||
1035 | mov eax, EMPTY_QUEUE |
970 | mov eax, EMPTY_QUEUE |
1036 | call dequeue |
971 | call dequeue |
1037 | cmp ax, NO_BUFFER |
972 | cmp ax, NO_BUFFER |
1038 | je sip_err_exit |
973 | je sip_err_exit |
1039 | 974 | ||
1040 | push eax |
975 | push eax |
1041 | 976 | ||
1042 | ; save the pointers to the data buffer & size |
977 | ; save the pointers to the data buffer & size |
1043 | push edx |
978 | push edx |
1044 | push ecx |
979 | push ecx |
1045 | 980 | ||
1046 | ; convert buffer pointer eax to the absolute address |
981 | ; convert buffer pointer eax to the absolute address |
1047 | mov ecx, IPBUFFSIZE |
982 | mov ecx, IPBUFFSIZE |
1048 | mul ecx |
983 | mul ecx |
1049 | add eax, IPbuffs |
984 | add eax, IPbuffs |
1050 | 985 | ||
1051 | mov edx, eax |
986 | mov edx, eax |
1052 | 987 | ||
1053 | ; So, edx holds the IPbuffer ptr |
988 | ; So, edx holds the IPbuffer ptr |
1054 | 989 | ||
1055 | pop ecx ; count of bytes to send |
990 | pop ecx ; count of bytes to send |
1056 | mov ebx, ecx ; need the length later |
991 | mov ebx, ecx ; need the length later |
1057 | pop eax ; get callers ptr to data to send |
992 | pop eax ; get callers ptr to data to send |
1058 | 993 | ||
1059 | ; Get the address of the callers data |
994 | ; Get the address of the callers data |
1060 | mov edi,[0x3010] |
995 | mov edi,[TASK_BASE] |
1061 | add edi,TASKDATA.mem_start |
996 | add edi,TASKDATA.mem_start |
1062 | add eax,[edi] |
997 | add eax,[edi] |
1063 | mov esi, eax |
998 | mov esi, eax |
1064 | 999 | ||
1065 | mov edi, edx |
1000 | mov edi, edx |
1066 | cld |
1001 | cld |
1067 | rep movsb ; copy the data across |
1002 | rep movsb ; copy the data across |
1068 | 1003 | ||
1069 | pop ebx |
1004 | pop ebx |
1070 | 1005 | ||
1071 | mov eax, IPIN_QUEUE |
1006 | mov eax, IPIN_QUEUE |
1072 | call queue |
1007 | call queue |
1073 | 1008 | ||
1074 | inc dword [ip_rx_count] |
1009 | inc dword [ip_rx_count] |
1075 | 1010 | ||
1076 | mov eax, 0 |
1011 | mov eax, 0 |
1077 | ret |
1012 | ret |
1078 | 1013 | ||
1079 | sip_err_exit: |
1014 | sip_err_exit: |
1080 | mov eax, 0xFFFFFFFF |
1015 | mov eax, 0xFFFFFFFF |
1081 | ret |
1016 | ret |
1082 | - | ||
1083 | - | ||
1084 | - | ||
1085 | ;*************************************************************************** |
- | |
1086 | ; Function |
- | |
1087 | ; socket_open |
- | |
1088 | ; |
- | |
1089 | ; Description |
- | |
1090 | ; find a free socket |
- | |
1091 | ; local port in ebx |
- | |
1092 | ; remote port in ecx |
- | |
1093 | ; remote ip in edx |
- | |
1094 | ; return socket # in eax, -1 if none available |
- | |
1095 | ; |
- | |
1096 | ;*************************************************************************** |
- | |
1097 | socket_open: |
- | |
1098 | call get_free_socket |
- | |
1099 | - | ||
1100 | cmp eax, 0xFFFFFFFF |
- | |
1101 | jz so_exit |
- | |
1102 | - | ||
1103 | ; ax holds the socket number that is free. Get real address |
- | |
1104 | push eax |
- | |
1105 | shl eax, 12 |
- | |
1106 | add eax, sockets |
- | |
1107 | - | ||
1108 | mov [eax], dword SOCK_OPEN |
- | |
1109 | - | ||
1110 | mov [eax + 12], byte bh ; Local port ( LS 16 bits ) |
- | |
1111 | mov [eax + 13], byte bl ; Local port ( LS 16 bits ) |
- | |
1112 | mov ebx, [stack_ip] |
- | |
1113 | mov [eax + 8], ebx ; Local IP |
- | |
1114 | mov [eax + 20], ch ; Remote Port ( LS 16 bits ) |
- | |
1115 | mov [eax + 21], cl ; Remote Port ( LS 16 bits ) |
- | |
1116 | mov [eax + 16], edx ; Remote IP ( in Internet order ) |
- | |
1117 | mov [eax + 24], dword 0 ; recieved data count |
- | |
1118 | - | ||
1119 | mov esi, [0x3010] |
- | |
1120 | mov ebx, [esi+TASKDATA.pid] |
- | |
1121 | mov [eax + 4], ebx ; save the process ID |
- | |
1122 | pop eax ; Get the socket number back, so we can return it |
- | |
1123 | - | ||
1124 | so_exit: |
- | |
1125 | ret |
- | |
1126 | - | ||
1127 | - | ||
1128 | - | ||
1129 | ;*************************************************************************** |
- | |
1130 | ; Function |
- | |
1131 | ; socket_open_tcp |
- | |
1132 | ; |
- | |
1133 | ; Description |
- | |
1134 | ; Opens a TCP socket in PASSIVE or ACTIVE mode |
- | |
1135 | ; find a free socket |
- | |
1136 | ; local port in ebx ( intel format ) |
- | |
1137 | ; remote port in ecx ( intel format ) |
- | |
1138 | ; remote ip in edx ( in Internet byte order ) |
- | |
1139 | ; Socket open mode in esi ( SOCKET_PASSIVE or SOCKET_ACTIVE ) |
- | |
1140 | ; return socket # in eax, -1 if none available |
- | |
1141 | ; |
- | |
1142 | ;*************************************************************************** |
- | |
1143 | socket_open_tcp: |
- | |
1144 | call get_free_socket |
- | |
1145 | - | ||
1146 | cmp eax, 0xFFFFFFFF |
- | |
1147 | jz so_exit |
- | |
1148 | - | ||
1149 | ; ax holds the socket number that is free. Get real address |
- | |
1150 | push eax |
- | |
1151 | shl eax, 12 |
- | |
1152 | add eax, sockets |
- | |
1153 | - | ||
1154 | mov [sktAddr], eax |
- | |
1155 | mov [eax], dword SOCK_OPEN |
- | |
1156 | - | ||
1157 | ; TODO - check this works! |
- | |
1158 | mov [eax + 72], dword 0 ; Reset the window timer. |
- | |
1159 | - | ||
1160 | mov [eax + 12], byte bh ; Local port ( LS 16 bits ) |
- | |
1161 | mov [eax + 13], byte bl ; Local port ( LS 16 bits ) |
- | |
1162 | mov ebx, [stack_ip] |
- | |
1163 | mov [eax + 8], ebx ; Local IP |
- | |
1164 | mov [eax + 20], ch ; Remote Port ( LS 16 bits ) |
- | |
1165 | mov [eax + 21], cl ; Remote Port ( LS 16 bits ) |
- | |
1166 | mov [eax + 16], edx ; Remote IP ( in Internet order ) |
- | |
1167 | mov [eax + 24], dword 0 ; recieved data count |
- | |
1168 | - | ||
1169 | ; Now fill in TCB state |
- | |
1170 | mov ebx, TCB_LISTEN |
- | |
1171 | cmp esi, SOCKET_PASSIVE |
- | |
1172 | jz sot_001 |
- | |
1173 | mov ebx, TCB_SYN_SENT |
- | |
1174 | - | ||
1175 | sot_001: |
- | |
1176 | mov [eax + 28], ebx ; Indicate the state of the TCB |
- | |
1177 | - | ||
1178 | mov esi, [0x3010] |
- | |
1179 | mov ecx, [esi+TASKDATA.pid] |
- | |
1180 | mov [eax + 4], ecx ; save the process ID |
- | |
1181 | - | ||
1182 | cmp ebx, TCB_LISTEN |
- | |
1183 | je sot_done |
- | |
1184 | - | ||
1185 | ; Now, if we are in active mode, then we have to send a SYN to the specified remote port |
- | |
1186 | - | ||
1187 | - | ||
1188 | mov eax, EMPTY_QUEUE |
- | |
1189 | call dequeue |
- | |
1190 | cmp ax, NO_BUFFER |
- | |
1191 | je sot_done |
- | |
1192 | - | ||
1193 | push eax |
- | |
1194 | - | ||
1195 | mov bl, 0x02 ; SYN |
- | |
1196 | mov ecx, 0 |
- | |
1197 | - | ||
1198 | call buildTCPPacket |
- | |
1199 | - | ||
1200 | mov eax, NET1OUT_QUEUE |
- | |
1201 | - | ||
1202 | mov edx, [stack_ip] |
- | |
1203 | mov ecx, [ sktAddr ] |
- | |
1204 | mov ecx, [ ecx + 16 ] |
- | |
1205 | cmp edx, ecx |
- | |
1206 | jne sot_notlocal |
- | |
1207 | mov eax, IPIN_QUEUE |
- | |
1208 | - | ||
1209 | sot_notlocal: |
- | |
1210 | ; Send it. |
- | |
1211 | pop ebx |
- | |
1212 | call queue |
- | |
1213 | - | ||
1214 | mov esi, [sktAddr] |
- | |
1215 | - | ||
1216 | ; increment SND.NXT in socket |
- | |
1217 | add esi, 48 |
- | |
1218 | call inc_inet_esi |
- | |
1219 | - | ||
1220 | sot_done: |
- | |
1221 | pop eax ; Get the socket number back, so we can return it |
- | |
1222 | - | ||
1223 | sot_exit: |
- | |
1224 | ret |
- | |
1225 | - | ||
1226 | - | ||
1227 | - | ||
1228 | ;*************************************************************************** |
- | |
1229 | ; Function |
- | |
1230 | ; socket_close |
- | |
1231 | ; |
- | |
1232 | ; Description |
- | |
1233 | ; socket # in ebx |
- | |
1234 | ; returns 0 for ok, -1 for socket not open (fail) |
- | |
1235 | ; |
- | |
1236 | ;*************************************************************************** |
- | |
1237 | socket_close: |
- | |
1238 | shl ebx, 12 |
- | |
1239 | add ebx, sockets |
- | |
1240 | mov eax, 0xFFFFFFFF ; assume this operation will fail.. |
- | |
1241 | cmp [ebx], dword SOCK_EMPTY |
- | |
1242 | jz sc_exit |
- | |
1243 | - | ||
1244 | ; Clear the socket varaibles |
- | |
1245 | xor eax, eax |
- | |
1246 | mov edi,ebx |
- | |
1247 | mov ecx,SOCKETHEADERSIZE |
- | |
1248 | cld |
- | |
1249 | rep stosb |
- | |
1250 | - | ||
1251 | sc_exit: |
- | |
1252 | ret |
- | |
1253 | - | ||
1254 | - | ||
1255 | - | ||
1256 | ;*************************************************************************** |
- | |
1257 | ; Function |
- | |
1258 | ; socket_close_tcp |
- | |
1259 | ; |
- | |
1260 | ; Description |
- | |
1261 | ; socket # in ebx |
- | |
1262 | ; returns 0 for ok, -1 for socket not open (fail) |
- | |
1263 | ; |
- | |
1264 | ;*************************************************************************** |
- | |
1265 | socket_close_tcp: |
- | |
1266 | ; first, remove any resend entries |
- | |
1267 | pusha |
- | |
1268 | - | ||
1269 | mov esi, resendQ |
- | |
1270 | mov ecx, 0 |
- | |
1271 | - | ||
1272 | sct001: |
- | |
1273 | cmp ecx, NUMRESENDENTRIES |
- | |
1274 | je sct003 ; None left |
- | |
1275 | cmp [esi], bl |
- | |
1276 | je sct002 ; found one |
- | |
1277 | inc ecx |
- | |
1278 | add esi, 4 |
- | |
1279 | jmp sct001 |
- | |
1280 | - | ||
1281 | sct002: |
- | |
1282 | dec dword [arp_rx_count] ; ************ TEST ONLY! |
- | |
1283 | - | ||
1284 | mov [esi], byte 0xFF |
- | |
1285 | jmp sct001 |
- | |
1286 | - | ||
1287 | sct003: |
- | |
1288 | popa |
- | |
1289 | - | ||
1290 | shl ebx, 12 |
- | |
1291 | add ebx, sockets |
- | |
1292 | mov [sktAddr], ebx |
- | |
1293 | mov eax, 0xFFFFFFFF ; assume this operation will fail.. |
- | |
1294 | cmp [ebx], dword SOCK_EMPTY |
- | |
1295 | jz sct_exit |
- | |
1296 | - | ||
1297 | ; Now construct the response, and queue for sending by IP |
- | |
1298 | mov eax, EMPTY_QUEUE |
- | |
1299 | call dequeue |
- | |
1300 | cmp ax, NO_BUFFER |
- | |
1301 | je stl_exit |
- | |
1302 | - | ||
1303 | push eax |
- | |
1304 | - | ||
1305 | mov bl, 0x11 ; FIN + ACK |
- | |
1306 | mov ecx, 0 |
- | |
1307 | mov esi, 0 |
- | |
1308 | - | ||
1309 | call buildTCPPacket |
- | |
1310 | - | ||
1311 | mov ebx, [sktAddr] |
- | |
1312 | - | ||
1313 | ; increament SND.NXT in socket |
- | |
1314 | mov esi, 48 |
- | |
1315 | add esi, ebx |
- | |
1316 | call inc_inet_esi |
- | |
1317 | - | ||
1318 | - | ||
1319 | ; Get the socket state |
- | |
1320 | mov eax, [ebx + 28] |
- | |
1321 | cmp eax, TCB_LISTEN |
- | |
1322 | je destroyTCB |
- | |
1323 | cmp eax, TCB_SYN_SENT |
- | |
1324 | je destroyTCB |
- | |
1325 | cmp eax, TCB_SYN_RECEIVED |
- | |
1326 | je sct_finwait1 |
- | |
1327 | cmp eax, TCB_ESTABLISHED |
- | |
1328 | je sct_finwait1 |
- | |
1329 | - | ||
1330 | ; assume CLOSE WAIT |
- | |
1331 | ; Send a fin, then enter last-ack state |
- | |
1332 | mov eax, TCB_LAST_ACK |
- | |
1333 | mov [ebx + 28], eax |
- | |
1334 | xor eax, eax |
- | |
1335 | jmp sct_send |
- | |
1336 | - | ||
1337 | sct_finwait1: |
- | |
1338 | ; Send a fin, then enter finwait2 state |
- | |
1339 | mov eax, TCB_FIN_WAIT_1 |
- | |
1340 | mov [ebx + 28], eax |
- | |
1341 | xor eax, eax |
- | |
1342 | - | ||
1343 | sct_send: |
- | |
1344 | mov eax, NET1OUT_QUEUE |
- | |
1345 | - | ||
1346 | mov edx, [stack_ip] |
- | |
1347 | mov ecx, [ sktAddr ] |
- | |
1348 | mov ecx, [ ecx + 16 ] |
- | |
1349 | cmp edx, ecx |
- | |
1350 | jne sct_notlocal |
- | |
1351 | mov eax, IPIN_QUEUE |
- | |
1352 | - | ||
1353 | sct_notlocal: |
- | |
1354 | ; Send it. |
- | |
1355 | pop ebx |
- | |
1356 | call queue |
- | |
1357 | jmp sct_exit |
- | |
1358 | - | ||
1359 | destroyTCB: |
- | |
1360 | pop eax |
- | |
1361 | ; Clear the socket varaibles |
- | |
1362 | xor eax, eax |
- | |
1363 | mov edi,ebx |
- | |
1364 | mov ecx,SOCKETHEADERSIZE |
- | |
1365 | cld |
- | |
1366 | rep stosb |
- | |
1367 | - | ||
1368 | sct_exit: |
- | |
1369 | ret |
- | |
1370 | - | ||
1371 | - | ||
1372 | - | ||
1373 | ;*************************************************************************** |
- | |
1374 | ; Function |
- | |
1375 | ; socket_poll |
- | |
1376 | ; |
- | |
1377 | ; Description |
- | |
1378 | ; socket # in ebx |
- | |
1379 | ; returns count in eax. |
- | |
1380 | ; |
- | |
1381 | ;*************************************************************************** |
- | |
1382 | socket_poll: |
- | |
1383 | shl ebx, 12 |
- | |
1384 | add ebx, sockets |
- | |
1385 | mov eax, [ebx + 24] |
- | |
1386 | - | ||
1387 | ret |
- | |
1388 | - | ||
1389 | - | ||
1390 | - | ||
1391 | ;*************************************************************************** |
- | |
1392 | ; Function |
- | |
1393 | ; socket_status |
- | |
1394 | ; |
- | |
1395 | ; Description |
- | |
1396 | ; socket # in ebx |
- | |
1397 | ; returns TCB state in eax. |
- | |
1398 | ; |
- | |
1399 | ;*************************************************************************** |
- | |
1400 | socket_status: |
- | |
1401 | shl ebx, 12 |
- | |
1402 | add ebx, sockets |
- | |
1403 | mov eax, [ebx + 28] |
- | |
1404 | - | ||
1405 | ret |
- | |
1406 | - | ||
1407 | - | ||
1408 | - | ||
1409 | ;*************************************************************************** |
- | |
1410 | ; Function |
- | |
1411 | ; socket_read |
- | |
1412 | ; |
- | |
1413 | ; Description |
- | |
1414 | ; socket # in ebx |
- | |
1415 | ; returns # of bytes remaining in eax, data in bl |
- | |
1416 | ; |
- | |
1417 | ;*************************************************************************** |
- | |
1418 | socket_read: |
- | |
1419 | shl ebx, 12 |
- | |
1420 | add ebx, sockets |
- | |
1421 | mov eax, [ebx + 24] ; get count of bytes |
- | |
1422 | mov ecx,1 |
- | |
1423 | test eax, eax |
- | |
1424 | jz sr2 |
- | |
1425 | - | ||
1426 | dec eax |
- | |
1427 | mov esi, ebx ; esi is address of socket |
- | |
1428 | mov [ebx + 24], eax ; store new count |
- | |
1429 | movzx ebx, byte [ebx + SOCKETHEADERSIZE] ; get the byte |
- | |
1430 | add esi, SOCKETHEADERSIZE |
- | |
1431 | mov edi, esi |
- | |
1432 | inc esi |
- | |
1433 | - | ||
1434 | mov ecx, (SOCKETBUFFSIZE - SOCKETHEADERSIZE) / 4 |
- | |
1435 | cld |
- | |
1436 | rep movsd |
- | |
1437 | xor ecx, ecx |
- | |
1438 | - | ||
1439 | sr1: |
- | |
1440 | jmp sor_exit |
- | |
1441 | - | ||
1442 | sr2: |
- | |
1443 | xor bl, bl |
- | |
1444 | - | ||
1445 | sor_exit: |
- | |
1446 | ret |
- | |
1447 | - | ||
1448 | - | ||
1449 | - | ||
1450 | ;*************************************************************************** |
- | |
1451 | ; Function |
- | |
1452 | ; socket_write |
- | |
1453 | ; |
- | |
1454 | ; Description |
- | |
1455 | ; socket in ebx |
- | |
1456 | ; # of bytes to write in ecx |
- | |
1457 | ; pointer to data in edx |
- | |
1458 | ; returns 0 in eax ok, -1 == failed ( invalid socket, or |
- | |
1459 | ; could not queue IP packet ) |
- | |
1460 | ; |
- | |
1461 | ;*************************************************************************** |
- | |
1462 | socket_write: |
- | |
1463 | ; First, find the address of the socket descriptor |
- | |
1464 | shl ebx, 12 |
- | |
1465 | add ebx, sockets ; ebx = address of actual socket |
- | |
1466 | - | ||
1467 | mov eax, 0xFFFFFFFF |
- | |
1468 | ; If the socket is invalid, return with an error code |
- | |
1469 | cmp [ebx], dword SOCK_EMPTY |
- | |
1470 | je sw_exit |
- | |
1471 | - | ||
1472 | - | ||
1473 | mov eax, EMPTY_QUEUE |
- | |
1474 | call dequeue |
- | |
1475 | cmp ax, NO_BUFFER |
- | |
1476 | je sw_exit |
- | |
1477 | - | ||
1478 | ; Save the queue entry number |
- | |
1479 | push eax |
- | |
1480 | - | ||
1481 | ; save the pointers to the data buffer & size |
- | |
1482 | push edx |
- | |
1483 | push ecx |
- | |
1484 | - | ||
1485 | ; convert buffer pointer eax to the absolute address |
- | |
1486 | mov ecx, IPBUFFSIZE |
- | |
1487 | mul ecx |
- | |
1488 | add eax, IPbuffs |
- | |
1489 | - | ||
1490 | mov edx, eax |
- | |
1491 | - | ||
1492 | ; So, ebx holds the socket ptr, edx holds the IPbuffer ptr |
- | |
1493 | - | ||
1494 | ; Fill in the IP header ( some data is in the socket descriptor) |
- | |
1495 | mov eax, [ebx + 8] |
- | |
1496 | mov [edx + 12], eax ; source IP |
- | |
1497 | mov eax, [ebx + 16] |
- | |
1498 | mov [edx + 16], eax ; Destination IP |
- | |
1499 | - | ||
1500 | mov al, 0x45 |
- | |
1501 | mov [edx], al ; Version, IHL |
- | |
1502 | xor al, al |
- | |
1503 | mov [edx + 1], al ; Type of service |
- | |
1504 | - | ||
1505 | pop eax ; Get the UDP data length |
- | |
1506 | push eax |
- | |
1507 | - | ||
1508 | add eax, 20 + 8 ; add IP header and UDP header lengths |
- | |
1509 | mov [edx + 2], ah |
- | |
1510 | mov [edx + 3], al |
- | |
1511 | xor al, al |
- | |
1512 | mov [edx + 4], al |
- | |
1513 | mov [edx + 5], al |
- | |
1514 | mov al, 0x40 |
- | |
1515 | mov [edx + 6], al |
- | |
1516 | xor al, al |
- | |
1517 | mov [edx + 7], al |
- | |
1518 | mov al, 0x20 |
- | |
1519 | mov [edx + 8], al |
- | |
1520 | mov al, 17 |
- | |
1521 | mov [edx + 9], al |
- | |
1522 | - | ||
1523 | ; Checksum left unfilled |
- | |
1524 | xor ax, ax |
- | |
1525 | mov [edx + 10], ax |
- | |
1526 | - | ||
1527 | ; Fill in the UDP header ( some data is in the socket descriptor) |
- | |
1528 | mov ax, [ebx + 12] |
- | |
1529 | mov [edx + 20], ax |
- | |
1530 | - | ||
1531 | mov ax, [ebx + 20] |
- | |
1532 | mov [edx + 20 + 2], ax |
- | |
1533 | - | ||
1534 | pop eax |
- | |
1535 | push eax |
- | |
1536 | - | ||
1537 | add eax, 8 |
- | |
1538 | mov [edx + 20 + 4], ah |
- | |
1539 | mov [edx + 20 + 5], al |
- | |
1540 | - | ||
1541 | ; Checksum left unfilled |
- | |
1542 | xor ax, ax |
- | |
1543 | mov [edx + 20 + 6], ax |
- | |
1544 | - | ||
1545 | pop ecx ; count of bytes to send |
- | |
1546 | mov ebx, ecx ; need the length later |
- | |
1547 | pop eax ; get callers ptr to data to send |
- | |
1548 | - | ||
1549 | ; Get the address of the callers data |
- | |
1550 | mov edi,[0x3010] |
- | |
1551 | add edi,TASKDATA.mem_start |
- | |
1552 | add eax,[edi] |
- | |
1553 | mov esi, eax |
- | |
1554 | - | ||
1555 | mov edi, edx |
- | |
1556 | add edi, 28 |
- | |
1557 | cld |
- | |
1558 | rep movsb ; copy the data across |
- | |
1559 | - | ||
1560 | ; we have edx as IPbuffer ptr. |
- | |
1561 | ; Fill in the UDP checksum |
- | |
1562 | ; First, fill in pseudoheader |
- | |
1563 | mov eax, [edx + 12] |
- | |
1564 | mov [pseudoHeader], eax |
- | |
1565 | mov eax, [edx + 16] |
- | |
1566 | mov [pseudoHeader+4], eax |
- | |
1567 | mov ax, 0x1100 ; 0 + protocol |
- | |
1568 | mov [pseudoHeader+8], ax |
- | |
1569 | add ebx, 8 |
- | |
1570 | mov eax, ebx |
- | |
1571 | mov [pseudoHeader+10], ah |
- | |
1572 | mov [pseudoHeader+11], al |
- | |
1573 | - | ||
1574 | mov eax, pseudoHeader |
- | |
1575 | mov [checkAdd1], eax |
- | |
1576 | mov [checkSize1], word 12 |
- | |
1577 | mov eax, edx |
- | |
1578 | add eax, 20 |
- | |
1579 | mov [checkAdd2], eax |
- | |
1580 | mov eax, ebx |
- | |
1581 | mov [checkSize2], ax ; was eax!! mjh 8/7/02 |
- | |
1582 | - | ||
1583 | call checksum |
- | |
1584 | - | ||
1585 | ; store it in the UDP checksum ( in the correct order! ) |
- | |
1586 | mov ax, [checkResult] |
- | |
1587 | - | ||
1588 | ; If the UDP checksum computes to 0, we must make it 0xffff |
- | |
1589 | ; (0 is reserved for 'not used') |
- | |
1590 | cmp ax, 0 |
- | |
1591 | jne sw_001 |
- | |
1592 | mov ax, 0xffff |
- | |
1593 | - | ||
1594 | sw_001: |
- | |
1595 | mov [edx + 20 + 6], ah |
- | |
1596 | mov [edx + 20 + 7], al |
- | |
1597 | - | ||
1598 | ; Fill in the IP header checksum |
- | |
1599 | mov eax, edx |
- | |
1600 | mov [checkAdd1], eax |
- | |
1601 | mov [checkSize1], word 20 |
- | |
1602 | mov [checkAdd2], dword 0 |
- | |
1603 | mov [checkSize2], word 0 |
- | |
1604 | - | ||
1605 | call checksum |
- | |
1606 | - | ||
1607 | mov ax, [checkResult] |
- | |
1608 | mov [edx + 10], ah |
- | |
1609 | mov [edx + 11], al |
- | |
1610 | - | ||
1611 | ; Check destination IP address. |
- | |
1612 | ; If it is the local host IP, route it back to IP_RX |
- | |
1613 | - | ||
1614 | pop ebx |
- | |
1615 | mov eax, NET1OUT_QUEUE |
- | |
1616 | - | ||
1617 | mov ecx, [ edx + 16] |
- | |
1618 | mov edx, [stack_ip] |
- | |
1619 | cmp edx, ecx |
- | |
1620 | jne sw_notlocal |
- | |
1621 | mov eax, IPIN_QUEUE |
- | |
1622 | - | ||
1623 | sw_notlocal: |
- | |
1624 | ; Send it. |
- | |
1625 | call queue |
- | |
1626 | - | ||
1627 | xor eax, eax |
- | |
1628 | - | ||
1629 | sw_exit: |
- | |
1630 | ret |
- | |
1631 | - | ||
1632 | - | ||
1633 | - | ||
1634 | ;*************************************************************************** |
- | |
1635 | ; Function |
- | |
1636 | ; socket_write_tcp |
- | |
1637 | ; |
- | |
1638 | ; Description |
- | |
1639 | ; socket in ebx |
- | |
1640 | ; # of bytes to write in ecx |
- | |
1641 | ; pointer to data in edx |
- | |
1642 | ; returns 0 in eax ok, -1 == failed ( invalid socket, or |
- | |
1643 | ; could not queue IP packet ) |
- | |
1644 | ; |
- | |
1645 | ;*************************************************************************** |
- | |
1646 | socket_write_tcp: |
- | |
1647 | ; First, find the address of the socket descriptor |
- | |
1648 | shl ebx, 12 |
- | |
1649 | add ebx, sockets ; ebx = address of actual socket |
- | |
1650 | - | ||
1651 | mov [sktAddr], ebx |
- | |
1652 | - | ||
1653 | mov eax, 0xFFFFFFFF |
- | |
1654 | ; If the socket is invalid, return with an error code |
- | |
1655 | cmp [ebx], dword SOCK_EMPTY |
- | |
1656 | je swt_exit |
- | |
1657 | - | ||
1658 | ; If the sockets window timer is nonzero, do not queue packet |
- | |
1659 | ; TODO - done |
- | |
1660 | cmp [ebx + 72], dword 0 |
- | |
1661 | jne swt_exit |
- | |
1662 | - | ||
1663 | mov eax, EMPTY_QUEUE |
- | |
1664 | call dequeue |
- | |
1665 | cmp ax, NO_BUFFER |
- | |
1666 | je swt_exit |
- | |
1667 | - | ||
1668 | push eax |
- | |
1669 | - | ||
1670 | mov bl, 0x10 ; ACK |
- | |
1671 | - | ||
1672 | ; Get the address of the callers data |
- | |
1673 | mov edi,[0x3010] |
- | |
1674 | add edi,TASKDATA.mem_start |
- | |
1675 | add edx,[edi] |
- | |
1676 | mov esi, edx |
- | |
1677 | - | ||
1678 | pop eax |
- | |
1679 | push eax |
- | |
1680 | - | ||
1681 | push ecx |
- | |
1682 | call buildTCPPacket |
- | |
1683 | pop ecx |
- | |
1684 | - | ||
1685 | ; Check destination IP address. |
- | |
1686 | ; If it is the local host IP, route it back to IP_RX |
- | |
1687 | - | ||
1688 | pop ebx |
- | |
1689 | push ecx |
- | |
1690 | mov eax, NET1OUT_QUEUE |
- | |
1691 | - | ||
1692 | mov edx, [stack_ip] |
- | |
1693 | mov ecx, [ sktAddr ] |
- | |
1694 | mov ecx, [ ecx + 16 ] |
- | |
1695 | cmp edx, ecx |
- | |
1696 | jne swt_notlocal |
- | |
1697 | mov eax, IPIN_QUEUE |
- | |
1698 | - | ||
1699 | swt_notlocal: |
- | |
1700 | pop ecx |
- | |
1701 | - | ||
1702 | push ebx ; save ipbuffer number |
- | |
1703 | - | ||
1704 | call queue |
- | |
1705 | - | ||
1706 | mov esi, [sktAddr] |
- | |
1707 | - | ||
1708 | ; increament SND.NXT in socket |
- | |
1709 | ; Amount to increment by is in ecx |
- | |
1710 | add esi, 48 |
- | |
1711 | call add_inet_esi |
- | |
1712 | - | ||
1713 | pop ebx |
- | |
1714 | - | ||
1715 | ; Copy the IP buffer to a resend queue |
- | |
1716 | ; If there isn't one, dont worry about it for now |
- | |
1717 | mov esi, resendQ |
- | |
1718 | mov ecx, 0 |
- | |
1719 | - | ||
1720 | swt003: |
- | |
1721 | cmp ecx, NUMRESENDENTRIES |
- | |
1722 | je swt001 ; None found |
- | |
1723 | cmp [esi], byte 0xFF |
- | |
1724 | je swt002 ; found one |
- | |
1725 | inc ecx |
- | |
1726 | add esi, 4 |
- | |
1727 | jmp swt003 |
- | |
1728 | - | ||
1729 | swt002: |
- | |
1730 | push ebx |
- | |
1731 | - | ||
1732 | ; OK, we have a buffer descriptor ptr in esi. |
- | |
1733 | ; resend entry # in ecx |
- | |
1734 | ; Populate it |
- | |
1735 | ; socket # |
- | |
1736 | ; retries count |
- | |
1737 | ; retry time |
- | |
1738 | ; fill IP buffer associated with this descriptor |
- | |
1739 | - | ||
1740 | mov eax, [sktAddr] |
- | |
1741 | sub eax, sockets |
- | |
1742 | shr eax, 12 ; get skt # |
- | |
1743 | mov [esi], al |
- | |
1744 | mov [esi + 1], byte TCP_RETRIES |
- | |
1745 | mov [esi + 2], word TCP_TIMEOUT |
- | |
1746 | - | ||
1747 | inc ecx |
- | |
1748 | ; Now get buffer location, and copy buffer across. argh! more copying,, |
- | |
1749 | mov edi, resendBuffer - IPBUFFSIZE |
- | |
1750 | swt002a: |
- | |
1751 | add edi, IPBUFFSIZE |
- | |
1752 | loop swt002a |
- | |
1753 | - | ||
1754 | ; we have dest buffer location in edi |
- | |
1755 | pop eax |
- | |
1756 | ; convert source buffer pointer eax to the absolute address |
- | |
1757 | mov ecx, IPBUFFSIZE |
- | |
1758 | mul ecx |
- | |
1759 | add eax, IPbuffs |
- | |
1760 | mov esi, eax |
- | |
1761 | - | ||
1762 | ; do copy |
- | |
1763 | mov ecx, IPBUFFSIZE |
- | |
1764 | cld |
- | |
1765 | rep movsb |
- | |
1766 | - | ||
1767 | inc dword [arp_rx_count] ; ************ TEST ONLY! |
- | |
1768 | - | ||
1769 | swt001: |
- | |
1770 | xor eax, eax |
- | |
1771 | - | ||
1772 | swt_exit: |
- | |
1773 | ret |
- | |
1774 | - | ||
1775 | - | ||
1776 | - | ||
1777 | ; Below, the main network layer source code is included |
- | |
1778 | ; |
- | |
1779 | - | ||
1780 | include "queue.inc" |
- | |
1781 | include "ip.inc" |
- | |
1782 | include "tcp.inc" |
- | |
1783 | include "udp.inc" |
- | |
1784 | include "eth_drv/ethernet.inc" |
- |