Rev 129 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 129 | Rev 384 | ||
---|---|---|---|
Line 11... | Line 11... | ||
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line -... | Line 20... | ||
- | 20 | ||
17 | 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: |
Line 25... | Line 29... | ||
25 | ; app_socket_handler |
29 | ; app_socket_handler |
26 | ; checksum |
30 | ; checksum |
27 | ; |
31 | ; |
28 | ;******************************************************************* |
32 | ;******************************************************************* |
Line -... | Line 33... | ||
- | 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 |
|
Line -... | Line 41... | ||
- | 41 | endg |
|
- | 42 | ||
- | 43 | ; socket buffers |
|
Line 29... | Line -... | ||
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 |
- | |
Line 143... | Line 45... | ||
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 |
Line 148... | Line 50... | ||
148 | BUFF_EMPTY equ 0 |
50 | BUFF_EMPTY equ 0 |
Line 149... | Line -... | ||
149 | BUFF_RX_FULL equ 1 |
- | |
150 | BUFF_ALLOCATED equ 2 |
- | |
151 | BUFF_TX_FULL equ 3 |
- | |
152 | - | ||
153 | 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. |
51 | BUFF_RX_FULL equ 1 |
179 | SOCKETHEADERSIZE equ 76 ; thus 4096 - SOCKETHEADERSIZE bytes data |
52 | BUFF_ALLOCATED equ 2 |
180 | 53 | BUFF_TX_FULL equ 3 |
|
181 | NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20 |
54 | |
182 | 55 | NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX |
|
Line 183... | Line 56... | ||
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 |
- | |
188 | NET1OUT_QUEUE equ 3 |
- | |
Line 189... | Line 60... | ||
189 | 60 | IPOUT_QUEUE equ 2 |
|
190 | NO_BUFFER equ 0xFFFF |
61 | NET1OUT_QUEUE equ 3 |
191 | IPBUFFSIZE equ 1500 ; MTU of an ethernet packet |
62 | |
Line 206... | Line 77... | ||
206 | stack_data equ 0x704000 |
77 | stack_data equ 0x704000 |
207 | stack_data_end equ 0x71ffff |
78 | stack_data_end equ 0x71ffff |
Line 208... | Line 79... | ||
208 | 79 | ||
209 | ; 32 bit word |
80 | ; 32 bit word |
- | 81 | stack_config equ stack_data |
|
210 | 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 |
- | |
213 | ; 1 byte. 0 == inactive, 1 = active |
- | |
- | 84 | stack_ip equ stack_data + 4 |
|
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 |
- | |
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 |
87 | ethernet_active equ stack_data + 9 |
222 | ; byte. |
- | |
223 | slip_rx_state equ stack_data + 20 ; no longer used |
88 | |
224 | ; byte |
- | |
225 | slip_tx_state equ stack_data + 21 ; no longer used |
- | |
226 | ; dword. Index into data |
- | |
227 | rx_data_ptr equ stack_data + 22 |
89 | |
228 | ; dword. Index into data |
- | |
229 | tx_data_ptr equ stack_data + 26 |
- | |
230 | ; word. Count of bytes to send |
- | |
- | 90 | ; TODO :: empty memory area |
|
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 |
Line 248... | Line 108... | ||
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 ) |
Line 265... | Line 125... | ||
265 | 125 | ||
266 | resendQ equ 0x770000 |
126 | resendQ equ 0x770000 |
Line -... | Line 127... | ||
- | 127 | resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
|
- | 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" |
|
267 | resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
152 | include "udp.inc" |
268 | 153 | include "socket.inc" |
|
269 | 154 | ||
270 | ;*************************************************************************** |
155 | ;*************************************************************************** |
271 | ; Function |
156 | ; Function |
Line 276... | Line 161... | ||
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 |
- | |
294 | - | ||
Line 295... | Line 166... | ||
295 | 166 | ||
296 | mov eax, 0xFFFFFFFF |
167 | stack_init: |
297 | mov [rx_buff_ptr], eax |
168 | ; Init two address spaces with default values |
298 | mov [tx_buff_ptr], eax |
- | |
299 | - | ||
300 | ; Put in some defaults : slip, 0x3f8, 4, ip=192.168.1.22 |
169 | _memset_dw stack_data_start, 0, 0x20000/4 |
301 | ; Saves me entering them each boot up when debugging |
- | |
302 | mov eax, 0x03f80401 |
- | |
303 | mov [stack_config], eax |
- | |
304 | mov eax, 0xc801a8c0 |
- | |
Line -... | Line 170... | ||
- | 170 | _memset_dw resendQ, 0xFFFFFFFF, NUMRESENDENTRIES |
|
305 | mov [stack_ip], eax |
171 | |
Line 306... | Line 172... | ||
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 |
- | |
312 | in al,0x71 |
177 | out 0x70, al |
Line 313... | Line 178... | ||
313 | mov [last_1sTick], al |
178 | in al, 0x71 |
Line 348... | Line 213... | ||
348 | cmp al, [last_1sTick] |
213 | cmp al, [last_1sTick] |
349 | je sh_exit |
214 | je sh_exit |
Line 350... | Line 215... | ||
350 | 215 | ||
Line 351... | Line 216... | ||
351 | mov [last_1sTick], al |
216 | mov [last_1sTick], al |
352 | 217 | ||
Line 353... | Line 218... | ||
353 | call arp_timer |
218 | stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0 |
354 | call tcp_tcb_handler |
219 | call tcp_tcb_handler |
Line -... | Line 220... | ||
- | 220 | ||
- | 221 | sh_exit: |
|
- | 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 |
|
Line -... | Line 231... | ||
- | 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] |
|
Line -... | Line 240... | ||
- | 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 |
|
Line 355... | Line -... | ||
355 | - | ||
356 | sh_exit: |
- | |
357 | ret |
- | |
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. |
245 | |
369 | ; This is useful when you want a to generate a unique local port |
246 | .loop: |
370 | ; number. |
247 | lodsw ;eax=word[esi],esi=esi+2 |
371 | ; On return, eax = 1 for free, 0 for in use |
- | |
372 | ; |
- | |
373 | ;*************************************************************************** |
- | |
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 |
248 | xchg ah,al ;cause must be a net byte-order |
407 | - | ||
408 | gfs1: |
- | |
Line 409... | Line -... | ||
409 | sub eax, SOCKETBUFFSIZE |
- | |
410 | cmp [eax + sockets], dword SOCK_EMPTY |
249 | add ebx, eax |
411 | loopnz gfs1 ; Return back if the socket is occupied |
- | |
412 | mov eax, ecx |
250 | loop .loop |
Line 413... | Line 251... | ||
413 | pop ecx |
251 | |
414 | jz gfs_exit |
252 | mov eax, ebx |
415 | mov eax, 0xFFFFFFFF |
253 | shr eax, 16 |
416 | 254 | add ax, bx |
|
Line 428... | Line 266... | ||
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 |
Line 441... | Line -... | ||
441 | - | ||
442 | mov eax, [checkAdd1] |
- | |
443 | 281 | ||
444 | cs1: |
282 | cs1: |
445 | mov bh, [eax] |
283 | mov bh, [eax] |
Line 446... | Line 284... | ||
446 | mov bl, [eax + 1] |
284 | mov bl, [eax + 1] |
Line 462... | Line 300... | ||
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 |
Line -... | Line 304... | ||
- | 304 | ||
- | 305 | mov eax, [checkAdd2] |
|
466 | 306 | ||
467 | shr cx, 1 |
307 | shr cx, 1 |
Line 468... | Line -... | ||
468 | jz cs2_1 |
- | |
469 | - | ||
470 | mov eax, [checkAdd2] |
308 | jz cs2_1 |
471 | 309 | ||
472 | cs2: |
310 | cs2: |
Line 473... | Line 311... | ||
473 | mov bh, [eax] |
311 | mov bh, [eax] |
Line 508... | Line 346... | ||
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 |
Line 523... | Line 361... | ||
523 | 361 | ||
524 | not0: |
362 | not0: |
Line 570... | Line 408... | ||
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 |
Line 574... | Line -... | ||
574 | - | ||
575 | not3: |
- | |
576 | cmp eax, 4 |
- | |
577 | jnz not4 |
- | |
578 | ; Enabled the slip driver on the comm port |
412 | |
579 | ; slip removed |
- | |
Line 580... | Line 413... | ||
580 | ret |
413 | ;old functions was deleted |
581 | - | ||
582 | not4: |
- | |
583 | cmp eax, 5 |
- | |
584 | jnz not5 |
- | |
585 | ; Disable the slip driver on the comm port |
- | |
586 | ; slip removed |
- | |
587 | 414 | ||
588 | not5: |
415 | not3: |
Line 589... | Line 416... | ||
589 | cmp eax, 6 |
416 | cmp eax, 6 |
590 | jnz not6 |
417 | jnz not6 |
Line 651... | Line 478... | ||
651 | mov eax, [dns_ip] |
478 | mov eax, [dns_ip] |
652 | ret |
479 | ret |
Line 653... | Line 480... | ||
653 | 480 | ||
654 | not13: |
481 | not13: |
655 | cmp eax, 14 |
482 | cmp eax, 14 |
Line 656... | Line 483... | ||
656 | jnz stack_driver_end |
483 | jnz not14 |
657 | 484 | ||
Line 658... | Line 485... | ||
658 | ; write the dns IP Address |
485 | ; write the dns IP Address |
Line -... | Line 486... | ||
- | 486 | mov [dns_ip], ebx |
|
- | 487 | ||
- | 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 |
|
659 | mov [dns_ip], ebx |
572 | |
660 | 573 | ret |
|
Line 661... | Line 574... | ||
661 | 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 | ; |
Line 744... | Line 657... | ||
744 | 657 | ||
745 | call is_localport_unused |
658 | call is_localport_unused |
Line 746... | Line 659... | ||
746 | ret |
659 | ret |
- | 660 | ||
- | 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 |
|
747 | 682 | ||
748 | nots9: |
683 | nots11: |
Line 749... | Line 684... | ||
749 | cmp eax, 254 |
684 | cmp eax, 254 |
Line 992... | Line 927... | ||
992 | pop edx |
927 | pop edx |
Line 993... | Line 928... | ||
993 | 928 | ||
Line 994... | Line 929... | ||
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 |
Line 999... | Line 934... | ||
999 | add edx,[edi] |
934 | add edx,[edi] |
Line 1055... | Line 990... | ||
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 |
Line 1058... | Line 993... | ||
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] |
Line 1063... | Line 998... | ||
1063 | mov esi, eax |
998 | mov esi, eax |
Line 1078... | Line 1013... | ||
1078 | 1013 | ||
1079 | sip_err_exit: |
1014 | sip_err_exit: |
1080 | mov eax, 0xFFFFFFFF |
1015 | mov eax, 0xFFFFFFFF |
Line 1081... | Line -... | ||
1081 | 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" |
- |