Rev 2465 | Rev 3589 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2465 | Rev 3555 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; STACK.INC ;; |
6 | ;; STACK.INC ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; TCP/IP stack for Menuet OS ;; |
8 | ;; TCP/IP stack for KolibriOS ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
10 | ;; Written by hidnplayr@kolibrios.org ;; |
11 | ;; ;; |
11 | ;; ;; |
- | 12 | ;; Some parts of code are based on the work of: ;; |
|
- | 13 | ;; Mike Hibbett (menuetos network stack) ;; |
|
- | 14 | ;; Eugen Brasoveanu (solar os network stack and drivers) ;; |
|
12 | ;; See file COPYING for details ;; |
15 | ;; mike.dld (kolibrios socket code) ;; |
13 | ;; ;; |
16 | ;; ;; |
14 | ;; Version 0.7 ;; |
- | |
15 | ;; Added a timer per socket to allow delays when rx window ;; |
- | |
16 | ;; gets below 1KB ;; |
17 | ;; TCP part is based on 4.4BSD ;; |
17 | ;; ;; |
18 | ;; ;; |
- | 19 | ;; GNU GENERAL PUBLIC LICENSE ;; |
|
18 | ;;10.01.2007 Bugfix for checksum function from Paolo Franchetti ;; |
20 | ;; Version 2, June 1991 ;; |
19 | ;; ;; |
21 | ;; ;; |
20 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 21... | Line 23... | ||
21 | 23 | ||
22 | $Revision: 2465 $ |
- | |
23 | - | ||
24 | - | ||
25 | ;******************************************************************* |
- | |
26 | ; Interface |
- | |
27 | ; The interfaces defined in ETHERNET.INC plus: |
- | |
28 | ; stack_init |
- | |
29 | ; stack_handler |
- | |
30 | ; app_stack_handler |
- | |
31 | ; app_socket_handler |
- | |
32 | ; checksum |
- | |
33 | ; |
- | |
Line 34... | Line 24... | ||
34 | ;******************************************************************* |
24 | $Revision: 3555 $ |
35 | - | ||
36 | uglobal |
- | |
37 | StackCounters: |
- | |
38 | dumped_rx_count dd 0 |
25 | |
39 | arp_tx_count: |
- | |
40 | dd 0 |
- | |
41 | arp_rx_count: |
- | |
42 | dd 0 |
- | |
43 | ip_rx_count: |
- | |
44 | dd 0 |
26 | uglobal |
45 | ip_tx_count: |
27 | net_10ms dd ? |
Line 46... | Line -... | ||
46 | dd 0 |
- | |
47 | endg |
- | |
48 | - | ||
49 | ; socket buffers |
- | |
50 | SOCKETBUFFSIZE equ 4096 ; state + config + buffer. |
- | |
51 | SOCKETHEADERSIZE equ SOCKET.rxData ; thus 4096 - SOCKETHEADERSIZE bytes data |
- | |
52 | - | ||
53 | ;NUM_SOCKETS equ 16 ; Number of open sockets supported. Was 20 |
- | |
54 | - | ||
55 | ; IPBUFF status values |
- | |
56 | BUFF_EMPTY equ 0 |
- | |
57 | BUFF_RX_FULL equ 1 |
- | |
58 | BUFF_ALLOCATED equ 2 |
- | |
59 | BUFF_TX_FULL equ 3 |
- | |
60 | - | ||
61 | NUM_IPBUFFERS equ 20 ; buffers allocated for TX/RX |
- | |
62 | - | ||
63 | NUMQUEUES equ 4 |
- | |
64 | - | ||
65 | EMPTY_QUEUE equ 0 |
28 | net_tmr_count dw ? |
66 | IPIN_QUEUE equ 1 |
- | |
67 | IPOUT_QUEUE equ 2 |
- | |
68 | NET1OUT_QUEUE equ 3 |
29 | endg |
69 | - | ||
70 | NO_BUFFER equ 0xFFFF |
- | |
71 | IPBUFFSIZE equ 1500 ; MTU of an ethernet packet |
- | |
72 | NUMQUEUEENTRIES equ NUM_IPBUFFERS |
- | |
73 | NUMRESENDENTRIES equ 18 ; Buffers for TCP resend packets |
- | |
74 | - | ||
75 | ; These are the 0x40 function codes for application access to the stack |
- | |
76 | STACK_DRIVER_STATUS equ 52 |
- | |
77 | SOCKET_INTERFACE equ 53 |
- | |
78 | - | ||
79 | - | ||
80 | ; 128KB allocated for the stack and network driver buffers and other |
- | |
81 | ; data requirements |
- | |
82 | ;stack_data_start equ 0x700000 |
- | |
83 | ;eth_data_start equ 0x700000 |
- | |
84 | ;stack_data equ 0x704000 |
- | |
85 | ;stack_data_end equ 0x71ffff |
- | |
86 | - | ||
87 | ; 32 bit word |
- | |
88 | stack_config equ stack_data |
- | |
89 | - | ||
90 | ; 32 bit word - IP Address in network format |
- | |
91 | stack_ip equ stack_data + 4 |
- | |
92 | - | ||
93 | ; 1 byte. 0 == inactive, 1 = active |
- | |
94 | ethernet_active equ stack_data + 9 |
- | |
95 | - | ||
96 | - | ||
97 | ; TODO :: empty memory area |
- | |
98 | - | ||
99 | ; Address of selected socket |
- | |
100 | ;sktAddr equ stack_data + 32 |
- | |
101 | ; Parameter to checksum routine - data ptr |
- | |
102 | checkAdd1 equ stack_data + 36 |
- | |
103 | ; Parameter to checksum routine - 2nd data ptr |
- | |
104 | checkAdd2 equ stack_data + 40 |
- | |
105 | ; Parameter to checksum routine - data size |
- | |
106 | checkSize1 equ stack_data + 44 |
- | |
107 | ; Parameter to checksum routine - 2nd data size |
- | |
108 | checkSize2 equ stack_data + 46 |
- | |
109 | ; result of checksum routine |
- | |
110 | checkResult equ stack_data + 48 |
- | |
111 | - | ||
112 | ; holds the TCP/UDP pseudo header. SA|DA|0|prot|UDP len| |
- | |
113 | pseudoHeader equ stack_data + 50 |
- | |
114 | - | ||
115 | ; receive and transmit IP buffer allocation |
- | |
116 | ;sockets equ stack_data + 62 |
- | |
117 | Next_free2 equ stack_data + 62;Next_free2 equ sockets + (SOCKETBUFFSIZE * NUM_SOCKETS) |
- | |
118 | ; 1560 byte buffer for rx / tx ethernet packets |
- | |
119 | Ether_buffer equ Next_free2 |
- | |
120 | Next_free3 equ Ether_buffer + 1518 |
- | |
121 | last_1sTick equ Next_free3 |
- | |
122 | IPbuffs equ Next_free3 + 1 |
- | |
123 | queues equ IPbuffs + ( NUM_IPBUFFERS * IPBUFFSIZE ) |
- | |
124 | queueList equ queues + (2 * NUMQUEUES) |
- | |
125 | last_1hsTick equ queueList + ( 2 * NUMQUEUEENTRIES ) |
- | |
126 | - | ||
127 | ;resendQ equ queueList + ( 2 * NUMQUEUEENTRIES ) |
- | |
128 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP |
- | |
129 | ; equ resendBuffer + ( IPBUFFSIZE * NUMRESENDENTRIES ) |
- | |
130 | - | ||
131 | - | ||
132 | - | ||
Line -... | Line 30... | ||
- | 30 | ||
- | 31 | MAX_NET_DEVICES = 16 |
|
- | 32 | ARP_BLOCK = 1 ; true or false |
|
- | 33 | ||
- | 34 | MIN_EPHEMERAL_PORT = 49152 |
|
- | 35 | MIN_EPHEMERAL_PORT_N = 0x00C0 ; same in Network byte order (FIXME) |
|
- | 36 | MAX_EPHEMERAL_PORT = 61000 |
|
- | 37 | MAX_EPHEMERAL_PORT_N = 0x48EE ; same in Network byte order (FIXME) |
|
- | 38 | ||
- | 39 | ; Ethernet protocol numbers |
|
- | 40 | ETHER_ARP = 0x0608 |
|
- | 41 | ETHER_IPv4 = 0x0008 |
|
- | 42 | ETHER_IPv6 = 0xDD86 |
|
- | 43 | ETHER_PPP_DISCOVERY = 0x6388 |
|
- | 44 | ETHER_PPP_SESSION = 0x6488 |
|
- | 45 | ||
- | 46 | ; PPP protocol numbers |
|
- | 47 | PPP_IPv4 = 0x2100 |
|
- | 48 | PPP_IPV6 = 0x5780 |
|
- | 49 | ||
- | 50 | ;Protocol family |
|
- | 51 | AF_UNSPEC = 0 |
|
- | 52 | AF_LOCAL = 1 |
|
- | 53 | AF_INET4 = 2 |
|
- | 54 | AF_INET6 = 10 |
|
- | 55 | AF_PPP = 777 |
|
- | 56 | ||
- | 57 | ; Internet protocol numbers |
|
- | 58 | IP_PROTO_IP = 0 |
|
- | 59 | IP_PROTO_ICMP = 1 |
|
- | 60 | IP_PROTO_TCP = 6 |
|
- | 61 | IP_PROTO_UDP = 17 |
|
- | 62 | ||
- | 63 | ; PPP protocol number |
|
- | 64 | PPP_PROTO_ETHERNET = 666 |
|
- | 65 | ||
- | 66 | ; Socket types |
|
- | 67 | SOCK_STREAM = 1 |
|
- | 68 | SOCK_DGRAM = 2 |
|
- | 69 | SOCK_RAW = 3 |
|
- | 70 | ||
- | 71 | ; Socket options |
|
- | 72 | SO_ACCEPTCON = 1 shl 0 |
|
- | 73 | SO_BROADCAST = 1 shl 1 |
|
- | 74 | SO_DEBUG = 1 shl 2 |
|
- | 75 | SO_DONTROUTE = 1 shl 3 |
|
- | 76 | SO_KEEPALIVE = 1 shl 4 |
|
- | 77 | SO_OOBINLINE = 1 shl 5 |
|
- | 78 | SO_REUSEADDR = 1 shl 6 |
|
- | 79 | SO_REUSEPORT = 1 shl 7 |
|
- | 80 | SO_USELOOPBACK = 1 shl 8 |
|
- | 81 | SO_BINDTODEVICE = 1 shl 9 |
|
- | 82 | ||
- | 83 | SO_BLOCK = 1 shl 10 ; TO BE REMOVED |
|
- | 84 | SO_NONBLOCK = 1 shl 31 |
|
- | 85 | ||
- | 86 | ; Socket flags for user calls |
|
- | 87 | MSG_PEEK = 0x02 |
|
- | 88 | MSG_DONTWAIT = 0x40 |
|
- | 89 | ||
- | 90 | ; Socket level |
|
- | 91 | SOL_SOCKET = 0 |
|
- | 92 | ||
- | 93 | ||
- | 94 | ; Socket States |
|
- | 95 | SS_NOFDREF = 0x0001 ; no file table ref any more |
|
- | 96 | SS_ISCONNECTED = 0x0002 ; socket connected to a peer |
|
- | 97 | SS_ISCONNECTING = 0x0004 ; in process of connecting to peer |
|
- | 98 | SS_ISDISCONNECTING = 0x0008 ; in process of disconnecting |
|
- | 99 | SS_CANTSENDMORE = 0x0010 ; can't send more data to peer |
|
- | 100 | SS_CANTRCVMORE = 0x0020 ; can't receive more data from peer |
|
- | 101 | SS_RCVATMARK = 0x0040 ; at mark on input |
|
- | 102 | SS_ISABORTING = 0x0080 ; aborting fd references - close() |
|
- | 103 | SS_RESTARTSYS = 0x0100 ; restart blocked system calls |
|
- | 104 | SS_ISDISCONNECTED = 0x0800 ; socket disconnected from peer |
|
- | 105 | ||
- | 106 | SS_ASYNC = 0x0100 ; async i/o notify |
|
- | 107 | SS_ISCONFIRMING = 0x0200 ; deciding to accept connection req |
|
- | 108 | SS_MORETOCOME = 0x0400 |
|
- | 109 | ||
- | 110 | SS_BLOCKED = 0x8000 |
|
- | 111 | ||
- | 112 | ||
- | 113 | SOCKET_MAXDATA = 4096*32 ; must be 4096*(power of 2) where 'power of 2' is at least 8 |
|
- | 114 | ||
- | 115 | ; Network driver types |
|
- | 116 | NET_TYPE_LOOPBACK = 0 |
|
- | 117 | NET_TYPE_ETH = 1 |
|
- | 118 | NET_TYPE_SLIP = 2 |
|
- | 119 | ||
- | 120 | MAX_backlog = 20 ; maximum backlog for stream sockets |
|
- | 121 | ||
- | 122 | ; Error Codes |
|
- | 123 | ENOBUFS = 55 |
|
- | 124 | ECONNREFUSED = 61 |
|
- | 125 | ECONNRESET = 52 |
|
- | 126 | ETIMEDOUT = 60 |
|
- | 127 | ECONNABORTED = 53 |
|
- | 128 | ||
- | 129 | ; Api protocol numbers |
|
- | 130 | API_ETH = 0 |
|
- | 131 | API_IPv4 = 1 |
|
- | 132 | API_ICMP = 2 |
|
- | 133 | API_UDP = 3 |
|
- | 134 | API_TCP = 4 |
|
- | 135 | API_ARP = 5 |
|
- | 136 | API_PPPOE = 6 |
|
- | 137 | API_IPv6 = 7 |
|
- | 138 | ||
- | 139 | HWACC_TCP_IPv4 = 1 shl 0 |
|
- | 140 | ||
- | 141 | struct NET_DEVICE |
|
- | 142 | ||
- | 143 | type dd ? ; Type field |
|
- | 144 | mtu dd ? ; Maximal Transmission Unit |
|
- | 145 | name dd ? ; Ptr to 0 terminated string |
|
- | 146 | ||
- | 147 | unload dd ? ; Ptrs to driver functions |
|
- | 148 | reset dd ? ; |
|
- | 149 | transmit dd ? ; |
|
- | 150 | ||
- | 151 | bytes_tx dq ? ; Statistics, updated by the driver |
|
- | 152 | bytes_rx dq ? ; |
|
- | 153 | packets_tx dd ? ; |
|
- | 154 | packets_rx dd ? ; |
|
- | 155 | ||
- | 156 | state dd ? ; link state (0 = no link) |
|
- | 157 | hwacc dd ? ; bitmask stating enabled HW accelerations (offload engines) |
|
- | 158 | ||
- | 159 | ends |
|
- | 160 | ||
- | 161 | ||
- | 162 | ; Exactly as it says.. |
|
- | 163 | macro pseudo_random reg { |
|
- | 164 | add reg, [esp] |
|
- | 165 | rol reg, 5 |
|
- | 166 | xor reg, [timer_ticks] |
|
- | 167 | ; add reg, [CPU_FREQ] |
|
Line -... | Line 168... | ||
- | 168 | imul reg, 214013 |
|
133 | ;resendQ equ 0x770000 |
169 | xor reg, 0xdeadbeef |
- | 170 | rol reg, 9 |
|
- | 171 | } |
|
- | 172 | ||
- | 173 | ; Network to Hardware byte order (dword) |
|
- | 174 | macro ntohd reg { |
|
- | 175 | ||
- | 176 | rol word reg, 8 |
|
- | 177 | rol dword reg, 16 |
|
134 | ;resendBuffer equ resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP ; XTODO: validate size |
178 | rol word reg , 8 |
135 | resendBuffer equ resendQ + ( 8 * NUMRESENDENTRIES ) ; for TCP |
179 | |
- | 180 | } |
|
Line 136... | Line -... | ||
136 | - | ||
137 | - | ||
138 | uglobal |
- | |
139 | net_sockets rd 2 |
- | |
140 | endg |
- | |
141 | - | ||
142 | ; simple macro for memory set operation |
- | |
143 | macro _memset_dw adr,value,amount |
- | |
144 | { |
- | |
145 | mov edi, adr |
- | |
146 | mov ecx, amount |
- | |
147 | if value = 0 |
- | |
148 | xor eax, eax |
181 | |
Line 149... | Line -... | ||
149 | else |
- | |
150 | mov eax, value |
- | |
151 | end if |
182 | ; Network to Hardware byte order (word) |
- | 183 | macro ntohw reg { |
|
- | 184 | ||
152 | cld |
185 | rol word reg, 8 |
- | 186 | ||
- | 187 | } |
|
- | 188 | ||
- | 189 | ||
- | 190 | include "queue.inc" |
|
- | 191 | ||
- | 192 | include "loopback.inc" |
|
153 | rep stosd |
193 | include "ethernet.inc" |
- | 194 | ||
- | 195 | include "PPPoE.inc" |
|
- | 196 | ||
154 | } |
197 | include "ARP.inc" |
Line -... | Line 198... | ||
- | 198 | include "IPv4.inc" |
|
- | 199 | include "IPv6.inc" |
|
- | 200 | ||
- | 201 | include "icmp.inc" |
|
- | 202 | include "udp.inc" |
|
- | 203 | include "tcp.inc" |
|
- | 204 | ||
- | 205 | include "socket.inc" |
|
- | 206 | ||
- | 207 | ||
- | 208 | ||
- | 209 | align 4 |
|
155 | 210 | uglobal |
|
156 | 211 | ||
157 | ; Below, the main network layer source code is included |
212 | NET_RUNNING dd ? |
158 | ; |
213 | NET_DEFAULT dd ? |
159 | include "queue.inc" |
- | |
160 | include "eth_drv/ethernet.inc" |
- | |
161 | include "ip.inc" |
- | |
162 | include "socket.inc" |
214 | NET_DRV_LIST rd MAX_NET_DEVICES |
163 | - | ||
164 | ;*************************************************************************** |
215 | |
165 | ; Function |
- | |
- | 216 | endg |
|
- | 217 | ||
166 | ; stack_init |
218 | |
- | 219 | ;----------------------------------------------------------------- |
|
- | 220 | ; |
|
167 | ; |
221 | ; stack_init |
168 | ; Description |
- | |
169 | ; Clear all allocated memory to zero. This ensures that |
- | |
170 | ; on startup, the stack is inactive, and consumes no resources |
- | |
Line -... | Line 222... | ||
- | 222 | ; |
|
- | 223 | ; This function calls all network init procedures |
|
171 | ; This is a kernel function, called prior to the OS main loop |
224 | ; |
172 | ; in set_variables |
225 | ; IN: / |
- | 226 | ; OUT: / |
|
- | 227 | ; |
|
- | 228 | ;----------------------------------------------------------------- |
|
- | 229 | align 4 |
|
- | 230 | stack_init: |
|
- | 231 | ||
- | 232 | ; Init the network drivers list |
|
- | 233 | xor eax, eax |
|
- | 234 | mov edi, NET_RUNNING |
|
- | 235 | mov ecx, (MAX_NET_DEVICES + 2) |
|
- | 236 | rep stosd |
|
Line 173... | Line 237... | ||
173 | ; |
237 | |
- | 238 | PPPoE_init |
|
174 | ;*************************************************************************** |
239 | |
Line 175... | Line -... | ||
175 | - | ||
176 | stack_init: |
- | |
177 | ; Init two address spaces with default values |
- | |
178 | _memset_dw stack_data_start, 0, 0x20000/4 |
- | |
179 | _memset_dw resendQ, 0, NUMRESENDENTRIES * 2 |
- | |
180 | 240 | IPv4_init |
|
Line -... | Line 241... | ||
- | 241 | ; IPv6_init |
|
- | 242 | ICMP_init |
|
- | 243 | ||
181 | mov [net_sockets], 0 |
244 | ARP_init |
- | 245 | UDP_init |
|
- | 246 | TCP_init |
|
182 | mov [net_sockets + 4], 0 |
247 | |
- | 248 | SOCKET_init |
|
- | 249 | ||
- | 250 | mov [net_tmr_count], 0 |
|
- | 251 | ||
- | 252 | ret |
|
183 | 253 | ||
184 | ; Queries initialization |
254 | |
185 | call queueInit |
- | |
186 | - | ||
187 | ; The following block sets up the 1s timer |
255 | |
188 | mov al, 0x0 |
256 | ; Wakeup every tick. |
- | 257 | proc stack_handler_has_work? |
|
- | 258 | ||
- | 259 | mov eax, [timer_ticks] |
|
189 | out 0x70, al |
260 | cmp eax, [net_10ms] |
190 | in al, 0x71 |
261 | |
191 | mov [last_1sTick], al |
262 | ret |
Line -... | Line 263... | ||
- | 263 | endp |
|
- | 264 | ||
192 | ret |
265 | |
193 | 266 | ;----------------------------------------------------------------- |
|
- | 267 | ; |
|
Line -... | Line 268... | ||
- | 268 | ; stack_handler |
|
- | 269 | ; |
|
Line 194... | Line 270... | ||
194 | 270 | ; This function is called in kernel loop |
|
195 | - | ||
196 | ;*************************************************************************** |
- | |
197 | ; Function |
- | |
198 | ; stack_handler |
- | |
199 | ; |
- | |
200 | ; Description |
- | |
201 | ; The kernel loop routine for the stack |
- | |
202 | ; This is a kernel function, called in the main loop |
- | |
203 | ; |
- | |
204 | ;*************************************************************************** |
- | |
205 | align 4 |
- | |
206 | stack_handler: |
- | |
207 | - | ||
208 | call ethernet_driver |
- | |
209 | call ip_rx |
271 | ; |
210 | - | ||
211 | - | ||
212 | ; Test for 10ms tick, call tcp timer |
- | |
213 | mov eax, [timer_ticks];[0xfdf0] |
- | |
214 | cmp eax, [last_1hsTick] |
- | |
215 | je sh_001 |
- | |
216 | - | ||
217 | mov [last_1hsTick], eax |
- | |
218 | call tcp_tx_handler |
- | |
219 | - | ||
220 | sh_001: |
- | |
221 | - | ||
222 | ; Test for 1 second event, call 1s timer functions |
- | |
223 | mov al, 0x0;second |
- | |
224 | out 0x70, al |
- | |
225 | in al, 0x71 |
- | |
226 | cmp al, [last_1sTick] |
- | |
227 | je sh_exit |
- | |
228 | - | ||
229 | mov [last_1sTick], al |
- | |
Line 230... | Line 272... | ||
230 | 272 | ; IN: / |
|
231 | stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0 |
- | |
232 | call tcp_tcb_handler |
- | |
233 | - | ||
234 | sh_exit: |
- | |
235 | ret |
- | |
236 | - | ||
237 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
238 | ;; Checksum [by Johnny_B] |
- | |
Line 239... | Line -... | ||
239 | ;; IN: |
- | |
240 | ;; buf_ptr=POINTER to buffer |
- | |
241 | ;; buf_size=SIZE of buffer |
273 | ; OUT: / |
242 | ;; OUT: |
- | |
243 | ;; AX=16-bit checksum |
274 | ; |
Line 244... | Line 275... | ||
244 | ;; Saves all used registers |
275 | ;----------------------------------------------------------------- |
245 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
276 | align 4 |
246 | proc checksum_jb stdcall uses ebx esi ecx,\ |
277 | stack_handler: |
247 | buf_ptr:DWORD, buf_size:DWORD |
- | |
Line -... | Line 278... | ||
- | 278 | ||
248 | 279 | ; Test for 10ms tick |
|
249 | xor eax, eax |
- | |
Line 250... | Line -... | ||
250 | xor ebx, ebx;accumulator |
- | |
251 | mov esi, dword[buf_ptr] |
- | |
252 | mov ecx, dword[buf_size] |
- | |
253 | shr ecx, 1; ecx=ecx/2 |
- | |
254 | jnc @f ; if CF==0 then size is even number |
- | |
255 | mov bh, byte[esi + ecx*2] |
- | |
256 | @@: |
- | |
257 | cld |
- | |
258 | - | ||
259 | .loop: |
- | |
260 | lodsw ;eax=word[esi],esi=esi+2 |
- | |
Line 261... | Line 280... | ||
261 | xchg ah, al;cause must be a net byte-order |
280 | mov eax, [timer_ticks] |
262 | add ebx, eax |
281 | cmp eax, [net_10ms] |
263 | loop .loop |
- | |
264 | - | ||
265 | mov eax, ebx |
- | |
266 | shr eax, 16 |
- | |
267 | add ax, bx |
- | |
268 | not ax |
- | |
Line 269... | Line -... | ||
269 | - | ||
270 | ret |
- | |
271 | endp |
282 | je .exit |
Line 272... | Line 283... | ||
272 | 283 | mov [net_10ms], eax |
|
273 | ;*************************************************************************** |
284 | |
Line 274... | Line 285... | ||
274 | ; Function |
285 | cmp [NET_RUNNING], 0 |
Line -... | Line 286... | ||
- | 286 | je .exit |
|
- | 287 | ||
- | 288 | test [net_10ms], 0x0f ; 160ms |
|
- | 289 | jnz .exit |
|
275 | ; checksum |
290 | |
276 | ; |
291 | TCP_timer_160ms |
- | 292 | ||
- | 293 | test [net_10ms], 0x3f ; 640ms |
|
277 | ; Description |
294 | jnz .exit |
Line 278... | Line -... | ||
278 | ; checkAdd1,checkAdd2, checkSize1, checkSize2, checkResult |
- | |
279 | ; Dont break anything; Most registers are used by the caller |
295 | |
Line 280... | Line -... | ||
280 | ; This code is derived from the 'C' source, cksum.c, in the book |
- | |
Line 281... | Line -... | ||
281 | ; Internetworking with TCP/IP Volume II by D.E. Comer |
- | |
282 | ; |
- | |
283 | ;*************************************************************************** |
- | |
284 | - | ||
Line -... | Line 296... | ||
- | 296 | TCP_timer_640ms |
|
- | 297 | ARP_decrease_entry_ttls |
|
- | 298 | IPv4_decrease_fragment_ttls |
|
- | 299 | ||
- | 300 | .exit: |
|
- | 301 | ret |
|
- | 302 | ||
- | 303 | ||
285 | 304 | ||
- | 305 | align 4 |
|
- | 306 | NET_link_changed: |
|
- | 307 | ||
- | 308 | DEBUGF 1,"NET_link_changed device=0x%x status=0x%x\n", ebx, [ebx + NET_DEVICE.state] |
|
Line 286... | Line -... | ||
286 | checksum: |
- | |
287 | pusha |
309 | |
Line 288... | Line -... | ||
288 | mov eax, [checkAdd1] |
- | |
289 | xor edx, edx ; edx is the accumulative checksum |
310 | align 4 |
290 | xor ebx, ebx |
311 | NET_send_event: |
Line -... | Line 312... | ||
- | 312 | ||
- | 313 | DEBUGF 1,"NET_send_event\n" |
|
291 | mov cx, [checkSize1] |
314 | |
- | 315 | ; Send event to all applications |
|
292 | shr cx, 1 |
316 | push edi ecx |
Line -... | Line 317... | ||
- | 317 | mov edi, SLOT_BASE |
|
293 | jz cs1_1 |
318 | mov ecx, [TASK_COUNT] |
Line -... | Line 319... | ||
- | 319 | .loop: |
|
- | 320 | add edi, 256 |
|
294 | 321 | or [edi + APPDATA.event_mask], EVENT_NETWORK2 |
|
295 | cs1: |
322 | loop .loop |
296 | mov bh, [eax] |
323 | pop ecx edi |
Line 297... | Line 324... | ||
297 | mov bl, [eax + 1] |
324 | |
298 | 325 | ret |
|
Line 299... | Line 326... | ||
299 | add eax, 2 |
326 | |
Line -... | Line 327... | ||
- | 327 | ||
300 | add edx, ebx |
328 | |
301 | 329 | ;----------------------------------------------------------------- |
|
Line 302... | Line -... | ||
302 | loopw cs1 |
- | |
303 | - | ||
304 | cs1_1: |
330 | ; |
305 | and word [checkSize1], 0x01 |
331 | ; NET_add_device: |
306 | jz cs_test2 |
332 | ; |
- | 333 | ; This function is called by the network drivers, |
|
307 | 334 | ; to register each running NIC to the kernel |
|
308 | mov bh, [eax] |
- | |
Line -... | Line 335... | ||
- | 335 | ; |
|
- | 336 | ; IN: Pointer to device structure in ebx |
|
- | 337 | ; OUT: Device num in eax, -1 on error |
|
309 | xor bl, bl |
338 | ; |
- | 339 | ;----------------------------------------------------------------- |
|
310 | 340 | align 4 |
|
- | 341 | NET_add_device: |
|
- | 342 | ||
- | 343 | DEBUGF 1,"NET_Add_Device: %x\n", ebx ;;; TODO: use mutex to lock net device list |
|
- | 344 | ||
311 | add edx, ebx |
345 | cmp [NET_RUNNING], MAX_NET_DEVICES |
Line -... | Line 346... | ||
- | 346 | jae .error |
|
- | 347 | ||
- | 348 | ;---------------------------------- |
|
- | 349 | ; Check if device is already listed |
|
Line 312... | Line 350... | ||
312 | 350 | mov eax, ebx |
|
- | 351 | mov ecx, MAX_NET_DEVICES ; We need to check whole list because a device may be removed without re-organizing list |
|
313 | cs_test2: |
352 | mov edi, NET_DRV_LIST |
- | 353 | ||
314 | mov cx, [checkSize2] |
354 | repne scasd ; See if device is already in the list |
315 | cmp cx, 0 |
355 | jz .error |
316 | jz cs_exit ; Finished if no 2nd buffer |
356 | |
317 | - | ||
318 | mov eax, [checkAdd2] |
357 | ;---------------------------- |
319 | 358 | ; Find empty slot in the list |
|
320 | shr cx, 1 |
359 | xor eax, eax |
321 | jz cs2_1 |
- | |
322 | 360 | mov ecx, MAX_NET_DEVICES |
|
323 | cs2: |
361 | mov edi, NET_DRV_LIST |
324 | mov bh, [eax] |
- | |
325 | mov bl, [eax + 1] |
- | |
326 | - | ||
327 | add eax, 2 |
- | |
328 | add edx, ebx |
- | |
329 | - | ||
330 | loopw cs2 |
- | |
331 | - | ||
332 | cs2_1: |
- | |
333 | and word [checkSize2], 0x01 |
- | |
334 | jz cs_exit |
- | |
335 | - | ||
336 | mov bh, [eax] |
- | |
337 | xor bl, bl |
- | |
338 | - | ||
339 | add edx, ebx |
- | |
340 | 362 | ||
341 | cs_exit: |
- | |
342 | mov ebx, edx |
- | |
343 | - | ||
344 | shr ebx, 16 |
- | |
345 | and edx, 0xffff |
363 | repne scasd |
Line 346... | Line 364... | ||
346 | add edx, ebx |
364 | jnz .error |
- | 365 | ||
Line -... | Line 366... | ||
- | 366 | sub edi, 4 |
|
- | 367 | ||
Line 347... | Line -... | ||
347 | mov eax, edx |
- | |
348 | shr eax, 16 |
368 | ;----------------------------- |
- | 369 | ; Add device to the found slot |
|
349 | add edx, eax |
370 | mov [edi], ebx ; add device to list |
350 | not dx |
371 | |
Line 351... | Line 372... | ||
351 | 372 | mov eax, edi ; Calculate device number in eax |
|
352 | mov [checkResult], dx |
373 | sub eax, NET_DRV_LIST |
353 | popa |
374 | shr eax, 2 |
354 | ret |
375 | |
Line 355... | Line -... | ||
355 | - | ||
356 | - | ||
357 | - | ||
Line -... | Line 376... | ||
- | 376 | inc [NET_RUNNING] ; Indicate that one more network device is up and running |
|
- | 377 | ||
- | 378 | cmp eax, 1 ; If it's the first network device, try to set it as default |
|
- | 379 | jne @f |
|
358 | 380 | push eax |
|
359 | ;*************************************************************************** |
381 | call NET_set_default |
- | 382 | pop eax |
|
360 | ; Function |
383 | @@: |
361 | ; app_stack_handler |
384 | |
- | 385 | call NET_send_event |
|
362 | ; |
386 | |
- | 387 | DEBUGF 1,"Device number: %u\n", eax |
|
363 | ; Description |
388 | ret |
Line 364... | Line -... | ||
364 | ; This is an application service, called by int 0x40, function 52 |
- | |
365 | ; It provides application access to the network interface layer |
- | |
366 | ; |
389 | |
367 | ;*************************************************************************** |
390 | .error: |
368 | iglobal |
- | |
369 | align 4 |
- | |
370 | f52call: |
- | |
Line 371... | Line -... | ||
371 | dd app_stack_handler.00 |
- | |
- | 391 | or eax, -1 |
|
372 | dd app_stack_handler.01 |
392 | DEBUGF 2,"Adding network device failed\n" |
373 | dd app_stack_handler.02 |
393 | ret |
- | 394 | ||
374 | dd app_stack_handler.03 |
395 | |
- | 396 | ||
375 | dd app_stack_handler.fail ;04 |
397 | ;----------------------------------------------------------------- |
- | 398 | ; |
|
- | 399 | ; NET_set_default |
|
- | 400 | ; |
|
376 | dd app_stack_handler.fail ;05 |
401 | ; API to set the default interface |
377 | dd stack_insert_packet ;app_stack_handler.06 |
402 | ; |
- | 403 | ; IN: Device num in eax |
|
378 | dd app_stack_handler.fail ;07 |
404 | ; OUT: Device num in eax, -1 on error |
379 | dd stack_get_packet ;app_stack_handler.08 |
405 | ; |
Line -... | Line 406... | ||
- | 406 | ;----------------------------------------------------------------- |
|
380 | dd app_stack_handler.09 |
407 | align 4 |
Line 381... | Line -... | ||
381 | dd app_stack_handler.10 |
- | |
382 | dd app_stack_handler.11 |
408 | NET_set_default: |
383 | dd app_stack_handler.12 |
409 | |
384 | dd app_stack_handler.13 |
410 | DEBUGF 1,"NET_set_default: device=%x\n", eax |
Line 385... | Line -... | ||
385 | dd app_stack_handler.14 |
- | |
386 | dd app_stack_handler.15 |
- | |
387 | endg |
411 | |
388 | app_stack_handler: |
412 | cmp eax, MAX_NET_DEVICES |
Line 389... | Line -... | ||
389 | ;in ebx,ecx |
- | |
390 | ;out eax |
413 | jae .error |
391 | cmp ebx, 15 |
- | |
392 | ja .fail ;if more than 15 then exit |
- | |
393 | - | ||
394 | jmp dword [f52call+ebx*4] |
414 | |
395 | - | ||
396 | - | ||
Line 397... | Line -... | ||
397 | .00: |
- | |
398 | ; Read the configuration word |
415 | cmp [NET_DRV_LIST+eax*4], 0 |
399 | mov eax, [stack_config] |
416 | je .error |
- | 417 | ||
400 | ret |
418 | mov [NET_DEFAULT], eax |
Line 401... | Line -... | ||
401 | - | ||
402 | .01: |
- | |
403 | ; read the IP address |
419 | |
404 | mov eax, [stack_ip] |
420 | DEBUGF 1,"NET_set_default: succes\n" |
Line 405... | Line 421... | ||
405 | ret |
421 | ret |
406 | - | ||
407 | .02: |
422 | |
408 | ; write the configuration word |
423 | .error: |
Line 409... | Line -... | ||
409 | mov [stack_config], ecx |
- | |
410 | - | ||
411 | ; |
- | |
412 | ; If ethernet now enabled, probe for the card, reset it and empty |
- | |
413 | ; the packet buffer |
- | |
414 | ; If all successfull, enable the card. |
- | |
Line 415... | Line -... | ||
415 | ; If ethernet now disabled, set it as disabled. Should really |
- | |
416 | ; empty the tcpip data area too. |
- | |
417 | - | ||
Line -... | Line 424... | ||
- | 424 | or eax, -1 |
|
- | 425 | DEBUGF 1,"NET_set_default: failed\n" |
|
418 | ; ethernet interface is '3' in ls 7 bits |
426 | ret |
- | 427 | ||
- | 428 | ||
419 | and cl, 0x7f |
429 | ;----------------------------------------------------------------- |
- | 430 | ; |
|
- | 431 | ; NET_Remove_Device: |
|
- | 432 | ; |
|
- | 433 | ; This function is called by etwork drivers, |
|
420 | cmp cl, 3 |
434 | ; to unregister network devices from the kernel |
Line 421... | Line -... | ||
421 | je ash_eth_enable |
- | |
422 | ; Ethernet isn't enabled, so make sure that the card is disabled |
- | |
423 | mov [ethernet_active], byte 0 |
- | |
424 | ret |
- | |
425 | 435 | ; |
|
426 | .03: |
436 | ; IN: Pointer to device structure in ebx |
Line -... | Line 437... | ||
- | 437 | ; OUT: eax: -1 on error |
|
427 | ; write the IP Address |
438 | ; |
428 | mov [stack_ip], ecx |
439 | ;----------------------------------------------------------------- |
429 | ret |
440 | align 4 |
430 | ;old functions was deleted |
441 | NET_remove_device: |
431 | ;.06: |
442 | |
Line 432... | Line -... | ||
432 | ; Insert an IP packet into the stacks received packet queue |
- | |
433 | ; call stack_insert_packet |
443 | cmp [NET_RUNNING], 0 |
Line 434... | Line -... | ||
434 | ; ret |
- | |
435 | - | ||
436 | ; Test for any packets queued for transmission over the network |
- | |
437 | - | ||
438 | ;.08: |
- | |
439 | ; call stack_get_packet |
- | |
440 | ; Extract a packet queued for transmission by the network |
- | |
441 | ; ret |
- | |
442 | - | ||
443 | .09: |
- | |
444 | ; read the gateway IP address |
- | |
445 | mov eax, [gateway_ip] |
- | |
446 | ret |
- | |
447 | - | ||
448 | .10: |
- | |
449 | ; read the subnet mask |
- | |
450 | mov eax, [subnet_mask] |
- | |
451 | ret |
- | |
452 | .11: |
- | |
453 | ; write the gateway IP Address |
- | |
454 | mov [gateway_ip], ecx |
- | |
455 | ret |
- | |
456 | - | ||
457 | .12: |
- | |
458 | ; write the subnet mask |
- | |
459 | mov [subnet_mask], ecx |
- | |
460 | ret |
- | |
461 | - | ||
462 | .13: |
- | |
463 | ; read the dns |
- | |
464 | mov eax, [dns_ip] |
- | |
465 | ret |
- | |
466 | - | ||
467 | .14: |
- | |
468 | ; write the dns IP Address |
- | |
469 | mov [dns_ip], ecx |
- | |
470 | ret |
- | |
471 | - | ||
472 | .15: |
444 | je .error |
473 | ; |
- | |
474 | ; in ecx we need 4 to read the last 2 bytes |
- | |
475 | ; or we need 0 to read the first 4 bytes |
- | |
476 | cmp ecx, 4 |
- | |
477 | ja .param_error |
- | |
478 | - | ||
479 | ; read MAC, returned (in mirrored byte order) in eax |
- | |
480 | mov eax, [node_addr + ecx] |
- | |
481 | ret |
- | |
482 | - | ||
483 | .param_error: |
- | |
484 | or eax, -1 ; params not accepted |
- | |
485 | ret |
- | |
486 | - | ||
487 | .16: |
- | |
488 | ; 0 -> arp_probe |
- | |
489 | ; 1 -> arp_announce |
- | |
490 | ; 2 -> arp_responce (not supported yet) |
- | |
491 | test ecx, ecx |
- | |
492 | je a_probe |
- | |
493 | - | ||
494 | dec ebx |
- | |
495 | jz a_ann ; arp announce |
- | |
496 | .fail: |
- | |
497 | or eax, -1 |
- | |
498 | ret |
- | |
499 | - | ||
500 | ; cmp ebx,2 |
- | |
501 | ; jne a_resp ; arp response |
- | |
502 | - | ||
503 | ; arp probe, sender IP must be set to 0.0.0.0, target IP is set to address being probed |
- | |
Line 504... | Line -... | ||
504 | ; ecx: pointer to target MAC, MAC should set to 0 by application |
- | |
505 | ; edx: target IP |
- | |
506 | a_probe: |
- | |
507 | push dword [stack_ip] |
- | |
508 | - | ||
509 | mov edx, [stack_ip] |
- | |
510 | and [stack_ip], dword 0 |
445 | |
511 | mov esi, ecx ; pointer to target MAC address |
- | |
512 | call arp_request |
- | |
513 | - | ||
514 | pop dword [stack_ip] |
- | |
515 | ret |
- | |
516 | - | ||
517 | ; arp announce, sender IP must be set to target IP |
- | |
518 | ; ecx: pointer to target MAC |
- | |
519 | a_ann: |
- | |
520 | mov edx, [stack_ip] |
446 | cmp [NET_DRV_LIST], ebx |
521 | mov esi, ecx ; pointer to target MAC address |
- | |
522 | call arp_request |
- | |
Line 523... | Line 447... | ||
523 | ret |
447 | jne @f |
- | 448 | mov [NET_DRV_LIST], 0 |
|
524 | 449 | cmp [NET_RUNNING], 1 |
|
- | 450 | je @f |
|
- | 451 | ; there are still active devices, find one and make it default |
|
525 | .17: |
452 | xor eax, eax |
526 | ; |
- | |
527 | ; modified by [smb] |
- | |
528 | - | ||
529 | ; |
- | |
Line 530... | Line 453... | ||
530 | ; ARPTable manager interface |
453 | mov ecx, MAX_NET_DEVICES |
531 | ;see "proc arp_table_manager" for more details |
- | |
532 | stdcall arp_table_manager, ecx, edx, esi;Opcode,Index,Extra |
- | |
533 | ret |
454 | mov edi, NET_DRV_LIST |
534 | ; |
455 | repe scasd |
535 | - | ||
536 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
537 | ash_eth_enable: |
- | |
538 | ; Probe for the card. This will reset it and enable the interface |
- | |
539 | ; if found |
- | |
540 | call eth_probe |
456 | je @f |
541 | test eax, eax |
- | |
542 | jz ash_eth_done ; Abort if no hardware found |
457 | shr edi, 2 |
543 | 458 | dec edi |
|
544 | mov [ethernet_active], byte 1 |
459 | mov [NET_DEFAULT], edi |
545 | ash_eth_done: |
460 | @@: |
546 | ret |
461 | |
547 | ;*************************************************************************** |
462 | ;---------------------------- |
- | 463 | ; Find the driver in the list |
|
- | 464 | ||
548 | ; Function |
465 | mov eax, ebx |
- | 466 | mov ecx, MAX_NET_DEVICES |
|
549 | ; app_socket_handler |
467 | mov edi, NET_DRV_LIST+4 |
550 | ; |
468 | |
551 | ; Description |
469 | repne scasd |
552 | ; This is an application service, called by int 0x40, function 53 |
- | |
553 | ; It provides application access to stack socket services |
- | |
554 | ; such as opening sockets |
- | |
555 | ; |
- | |
Line -... | Line 470... | ||
- | 470 | jnz .error |
|
- | 471 | ||
- | 472 | ;------------------------ |
|
- | 473 | ; Remove it from the list |
|
- | 474 | ||
- | 475 | xor eax, eax |
|
- | 476 | mov dword [edi-4], eax |
|
- | 477 | ||
- | 478 | call NET_send_event |
|
- | 479 | ||
- | 480 | dec [NET_RUNNING] |
|
Line 556... | Line -... | ||
556 | ;*************************************************************************** |
- | |
557 | iglobal |
481 | ret |
558 | align 4 |
- | |
559 | f53call: |
482 | |
560 | dd socket_open ;00 |
483 | .error: |
561 | dd socket_close ;01 |
- | |
Line -... | Line 484... | ||
- | 484 | or eax, -1 |
|
- | 485 | ret |
|
Line 562... | Line -... | ||
562 | dd socket_poll ;02 |
- | |
563 | dd socket_read ;03 |
486 | |
564 | dd socket_write ;04 |
487 | |
Line 565... | Line -... | ||
565 | dd socket_open_tcp ;05 |
- | |
566 | dd socket_status ;06 |
488 | |
567 | dd socket_write_tcp ;07 |
489 | ;----------------------------------------------------------------- |
568 | dd socket_close_tcp ;08 |
- | |
Line 569... | Line -... | ||
569 | dd is_localport_unused ;09 |
- | |
570 | dd app_socket_handler.10 |
490 | ; |
571 | dd socket_read_packet ;11 |
491 | ; NET_ptr_to_num |
Line 572... | Line -... | ||
572 | endg |
- | |
573 | 492 | ; |
|
574 | app_socket_handler: |
493 | ; IN: ebx = ptr to device struct |
575 | ;in ebx,ecx,edx,wsi |
- | |
Line 576... | Line -... | ||
576 | ;out eax |
- | |
577 | cmp eax, 255 |
494 | ; OUT: edi = -1 on error, device number otherwise |
578 | je stack_internal_status |
- | |
Line 579... | Line -... | ||
579 | - | ||
580 | cmp eax, 11 |
495 | ; |
581 | ja .fail ;if more than 15 then exit |
496 | ;----------------------------------------------------------------- |
582 | 497 | align 4 |
|
Line 583... | Line -... | ||
583 | jmp dword [f53call+eax*4] |
- | |
584 | 498 | NET_ptr_to_num: |
|
585 | .10: |
499 | push ecx |
Line 586... | Line -... | ||
586 | mov eax, dword[drvr_cable] |
- | |
587 | test eax, eax |
500 | |
588 | jnz @f ; if function is not implented, return -1 |
501 | mov ecx, MAX_NET_DEVICES |
589 | or al, -1 |
- | |
Line 590... | Line -... | ||
590 | ret |
- | |
591 | @@: |
502 | mov edi, NET_DRV_LIST |
592 | jmp dword[drvr_cable] |
503 | |
Line -... | Line 504... | ||
- | 504 | .loop: |
|
- | 505 | cmp ebx, [edi] |
|
- | 506 | jz .found |
|
- | 507 | add edi, 4 |
|
593 | 508 | dec ecx |
|
594 | .fail: |
509 | jnz .loop |
- | 510 | ||
- | 511 | ; repnz scasd could work too if eax is used instead of ebx! |
|
595 | or eax, -1 |
512 | |
- | 513 | or edi, -1 |
|
Line 596... | Line 514... | ||
596 | ret |
514 | |
597 | uglobal |
515 | pop ecx |
598 | ARPTmp: |
516 | ret |
Line 599... | Line 517... | ||
599 | times 14 db 0 |
517 | |
600 | endg |
518 | .found: |
- | 519 | sub edi, NET_DRV_LIST |
|
601 | 520 | shr edi, 2 |
|
Line -... | Line 521... | ||
- | 521 | ||
- | 522 | pop ecx |
|
602 | ;*************************************************************************** |
523 | ret |
- | 524 | ||
- | 525 | ;----------------------------------------------------------------- |
|
- | 526 | ; |
|
603 | ; Function |
527 | ; checksum_1 |
604 | ; stack_internal_status |
528 | ; |
- | 529 | ; This is the first of two functions needed to calculate a checksum. |
|
- | 530 | ; |
|
- | 531 | ; IN: edx = start offset for semi-checksum |
|
- | 532 | ; esi = pointer to data |
|
Line 605... | Line 533... | ||
605 | ; |
533 | ; ecx = data size |
- | 534 | ; OUT: edx = semi-checksum |
|
606 | ; Description |
535 | ; |
- | 536 | ; |
|
- | 537 | ; Code was optimized by diamond |
|
607 | ; Returns information about the internal status of the stack |
538 | ; |
- | 539 | ;----------------------------------------------------------------- |
|
- | 540 | align 4 |
|
- | 541 | checksum_1: |
|
- | 542 | ||
- | 543 | shr ecx, 1 |
|
- | 544 | pushf |
|
- | 545 | jz .no_2 |
|
- | 546 | ||
Line 608... | Line -... | ||
608 | ; This is only useful for debugging |
- | |
609 | ; It works with the ethernet driver |
547 | shr ecx, 1 |
610 | ; sub function in ebx |
- | |
Line 611... | Line -... | ||
611 | ; return requested data in eax |
- | |
612 | ; |
- | |
613 | ;*************************************************************************** |
- | |
614 | ; This sub function allows access to debugging information on the stack |
- | |
615 | ; ecx holds the request: |
- | |
616 | ; 100 : return length of empty queue |
- | |
617 | ; 101 : return length of IPOUT QUEUE |
- | |
618 | ; 102 : return length of IPIN QUEUE |
- | |
619 | ; 103 : return length of NET1OUT QUEUE |
548 | pushf |
Line 620... | Line -... | ||
620 | ; 200 : return # of ARP entries |
- | |
621 | ; 201 : return size of ARP table ( max # entries ) |
- | |
622 | ; 202 : select ARP table entry # |
- | |
Line 623... | Line -... | ||
623 | ; 203 : return IP of selected table entry |
- | |
624 | ; 204 : return High 4 bytes of MAC address of selected table entry |
- | |
625 | ; 205 : return low 2 bytes of MAC address of selected table entry |
- | |
Line -... | Line 549... | ||
- | 549 | jz .no_4 |
|
626 | ; 206 : return status word of selected table entry |
550 | |
627 | ; 207 : return Time to live of selected table entry |
551 | shr ecx, 1 |
- | 552 | pushf |
|
- | 553 | jz .no_8 |
|
- | 554 | ||
628 | 555 | .loop: |
|
Line 629... | Line -... | ||
629 | - | ||
630 | ; 2 : return number of IP packets received |
556 | add dl, [esi+1] |
631 | ; 3 : return number of packets transmitted |
557 | adc dh, [esi+0] |
Line 632... | Line -... | ||
632 | ; 4 : return number of received packets dumped |
- | |
633 | ; 5 : return number of arp packets received |
558 | |
634 | ; 6 : return status of packet driver |
559 | adc dl, [esi+3] |
Line 635... | Line 560... | ||
635 | ; ( 0 == not active, FFFFFFFF = successful ) |
560 | adc dh, [esi+2] |
636 | 561 | ||
637 | 562 | adc dl, [esi+5] |
|
Line 638... | Line 563... | ||
638 | stack_internal_status: |
563 | adc dh, [esi+4] |
639 | cmp ebx, 100 |
564 | |
640 | jnz notsis100 |
565 | adc dl, [esi+7] |
Line 641... | Line 566... | ||
641 | 566 | adc dh, [esi+6] |
|
642 | ; 100 : return length of EMPTY QUEUE |
567 | |
643 | mov ebx, EMPTY_QUEUE |
- | |
Line 644... | Line -... | ||
644 | call queueSize |
- | |
645 | ret |
568 | adc edx, 0 |
646 | - | ||
Line 647... | Line 569... | ||
647 | notsis100: |
569 | add esi, 8 |
648 | cmp ebx, 101 |
570 | |
649 | jnz notsis101 |
571 | dec ecx |
- | 572 | jnz .loop |
|
Line 650... | Line 573... | ||
650 | 573 | ||
- | 574 | adc edx, 0 |
|
- | 575 | ||
651 | ; 101 : return length of IPOUT QUEUE |
576 | .no_8: |
- | 577 | popf |
|
- | 578 | jnc .no_4 |
|
- | 579 | ||
652 | mov ebx, IPOUT_QUEUE |
580 | add dl, [esi+1] |
- | 581 | adc dh, [esi+0] |
|
Line 653... | Line 582... | ||
653 | call queueSize |
582 | |
654 | ret |
- | |
655 | - | ||
Line 656... | Line -... | ||
656 | notsis101: |
- | |
657 | cmp ebx, 102 |
583 | adc dl, [esi+3] |
658 | jnz notsis102 |
584 | adc dh, [esi+2] |
Line 659... | Line -... | ||
659 | - | ||
660 | ; 102 : return length of IPIN QUEUE |
- | |
661 | mov ebx, IPIN_QUEUE |
- | |
Line 662... | Line -... | ||
662 | call queueSize |
- | |
663 | ret |
- | |
664 | 585 | ||
Line 665... | Line -... | ||
665 | notsis102: |
- | |
666 | cmp ebx, 103 |
586 | adc edx, 0 |
667 | jnz notsis103 |
587 | add esi, 4 |
Line 668... | Line -... | ||
668 | - | ||
669 | ; 103 : return length of NET1OUT QUEUE |
588 | |
670 | mov ebx, NET1OUT_QUEUE |
589 | .no_4: |
Line 671... | Line -... | ||
671 | call queueSize |
- | |
672 | ret |
590 | popf |
673 | 591 | jnc .no_2 |
|
Line 674... | Line -... | ||
674 | notsis103: |
- | |
675 | cmp ebx, 200 |
- | |
676 | jnz notsis200 |
592 | |
Line 677... | Line -... | ||
677 | - | ||
678 | ; 200 : return num entries in arp table |
- | |
679 | movzx eax, byte [NumARP] |
593 | add dl, [esi+1] |
680 | ret |
594 | adc dh, [esi+0] |
Line 681... | Line -... | ||
681 | - | ||
682 | notsis200: |
595 | |
683 | cmp ebx, 201 |
- | |
Line -... | Line 596... | ||
- | 596 | adc edx, 0 |
|
- | 597 | inc esi |
|
Line 684... | Line -... | ||
684 | jnz notsis201 |
- | |
685 | - | ||
686 | ; 201 : return arp table size |
- | |
687 | mov eax, 20; ARP_TABLE_SIZE |
- | |
688 | ret |
- | |
689 | - | ||
690 | notsis201: |
- | |
691 | cmp ebx, 202 |
- | |
692 | jnz notsis202 |
- | |
693 | - | ||
694 | ; 202 - read the requested table entry |
- | |
695 | ; into a temporary buffer |
- | |
696 | ; ecx holds the entry number |
- | |
697 | - | ||
698 | mov eax, ecx |
- | |
699 | mov ecx, 14; ARP_ENTRY_SIZE |
- | |
700 | mul ecx |
- | |
701 | - | ||
702 | mov ecx, [eax + ARPTable] |
- | |
703 | mov [ARPTmp], ecx |
- | |
704 | mov ecx, [eax + ARPTable+4] |
- | |
705 | mov [ARPTmp+4], ecx |
- | |
706 | mov ecx, [eax + ARPTable+8] |
- | |
707 | mov [ARPTmp+8], ecx |
- | |
708 | mov cx, [eax + ARPTable+12] |
- | |
709 | mov [ARPTmp+12], cx |
- | |
710 | ret |
- | |
711 | 598 | inc esi |
|
712 | notsis202: |
- | |
713 | cmp ebx, 203 |
- | |
714 | jnz notsis203 |
- | |
715 | - | ||
716 | ; 203 - return IP address |
- | |
717 | mov eax, [ARPTmp] |
- | |
Line 718... | Line -... | ||
718 | ret |
- | |
719 | 599 | ||
720 | notsis203: |
- | |
721 | cmp ebx, 204 |
- | |
Line 722... | Line -... | ||
722 | jnz notsis204 |
- | |
723 | - | ||
724 | ; 204 - return MAC high dword |
- | |
Line 725... | Line 600... | ||
725 | mov eax, [ARPTmp+4] |
600 | .no_2: |
726 | ret |
- | |
Line 727... | Line -... | ||
727 | - | ||
728 | notsis204: |
601 | popf |
- | 602 | jnc .end |
|
- | 603 | ||
- | 604 | add dh, [esi+0] |
|
- | 605 | adc edx, 0 |
|
- | 606 | .end: |
|
- | 607 | ret |
|
- | 608 | ||
- | 609 | ;----------------------------------------------------------------- |
|
- | 610 | ; |
|
- | 611 | ; checksum_2 |
|
- | 612 | ; |
|
- | 613 | ; This function calculates the final ip/tcp/udp checksum for you |
|
- | 614 | ; |
|
729 | cmp ebx, 205 |
615 | ; IN: edx = semi-checksum |
Line -... | Line 616... | ||
- | 616 | ; OUT: dx = checksum (in INET byte order) |
|
- | 617 | ; |
|
- | 618 | ;----------------------------------------------------------------- |
|
- | 619 | align 4 |
|
- | 620 | checksum_2: |
|
- | 621 | ||
- | 622 | mov ecx, edx |
|
- | 623 | shr ecx, 16 |
|
- | 624 | and edx, 0xffff |
|
Line 730... | Line -... | ||
730 | jnz notsis205 |
- | |
731 | - | ||
732 | ; 205 - return MAC ls word |
- | |
733 | movzx eax, word [ARPTmp+8] |
- | |
734 | ret |
- | |
735 | - | ||
736 | notsis205: |
625 | add edx, ecx |
737 | cmp ebx, 206 |
626 | |
738 | jnz notsis206 |
627 | mov ecx, edx |
739 | - | ||
740 | ; 206 - return status word |
628 | shr ecx, 16 |
741 | movzx eax, word [ARPTmp+10] |
- | |
742 | ret |
- | |
743 | - | ||
744 | notsis206: |
- | |
745 | cmp ebx, 207 |
- | |
746 | jnz notsis207 |
629 | add dx, cx |
Line 747... | Line 630... | ||
747 | 630 | test dx, dx ; it seems that ZF is not set when CF is set :( |
|
Line 748... | Line 631... | ||
748 | ; 207 - return ttl word |
631 | not dx |
749 | movzx eax, word [ARPTmp+12] |
- | |
750 | ret |
632 | jnz .not_zero |
Line 751... | Line -... | ||
751 | - | ||
752 | notsis207: |
633 | dec dx |
753 | cmp ebx, 2 |
634 | .not_zero: |
754 | jnz notsis2 |
- | |
Line -... | Line 635... | ||
- | 635 | xchg dl, dh |
|
755 | 636 | ||
Line 756... | Line 637... | ||
756 | ; 2 : return number of IP packets received |
637 | DEBUGF 1,"Checksum: %x\n", dx |
- | 638 | ||
Line 757... | Line 639... | ||
757 | mov eax, [ip_rx_count] |
639 | ret |
758 | ret |
640 | |
759 | - | ||
Line 760... | Line -... | ||
760 | notsis2: |
- | |
761 | cmp ebx, 3 |
- | |
762 | jnz notsis3 |
- | |
763 | 641 | ||
764 | ; 3 : return number of packets transmitted |
642 | |
Line 765... | Line 643... | ||
765 | mov eax, [ip_tx_count] |
643 | ;---------------------------------------------------------------- |
766 | ret |
644 | ; |
767 | - | ||
Line -... | Line 645... | ||
- | 645 | ; System function to work with network devices (75) |
|
768 | notsis3: |
646 | ; |
Line 769... | Line 647... | ||
769 | cmp ebx, 4 |
647 | ;---------------------------------------------------------------- |
770 | jnz notsis4 |
648 | align 4 |
Line 771... | Line 649... | ||
771 | 649 | sys_network: ; FIXME: make default device easily accessible |
|
Line 772... | Line 650... | ||
772 | ; 4 : return number of received packets dumped |
650 | |
773 | mov eax, [dumped_rx_count] |
651 | cmp ebx, -1 |
Line 774... | Line 652... | ||
774 | ret |
652 | jne @f |
775 | 653 | ||
776 | notsis4: |
654 | mov eax, [NET_RUNNING] |
777 | cmp ebx, 5 |
- |