Rev 1635 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1635 | Rev 2434 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
16 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
17 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
17 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
18 | ;; ;; |
18 | ;; ;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 20... | Line 20... | ||
20 | 20 | ||
Line 21... | Line 21... | ||
21 | $Revision: 983 $ |
21 | $Revision: 2434 $ |
22 | 22 | ||
23 | 23 | ||
Line 65... | Line 65... | ||
65 | ;example, static entry -> db 11,22,33,44, 0x11,0x22,0x33,0x44,0x55,0x66, 0x01,0x00, 0xFF,0xFF |
65 | ;example, static entry -> db 11,22,33,44, 0x11,0x22,0x33,0x44,0x55,0x66, 0x01,0x00, 0xFF,0xFF |
66 | times ( ARP_TABLE_SIZE - ARP_TABLE_ENTRIES ) * ARP_ENTRY_SIZE db 0 |
66 | times ( ARP_TABLE_SIZE - ARP_TABLE_ENTRIES ) * ARP_ENTRY_SIZE db 0 |
67 | endg |
67 | endg |
Line 68... | Line 68... | ||
68 | 68 | ||
- | 69 | iglobal |
|
69 | iglobal |
70 | NumARP: |
70 | NumARP: dd ARP_TABLE_ENTRIES |
71 | dd ARP_TABLE_ENTRIES |
71 | ARPTable_ptr dd ARPTable ;pointer to ARPTable |
72 | ARPTable_ptr dd ARPTable ;pointer to ARPTable |
Line 72... | Line 73... | ||
72 | endg |
73 | endg |
73 | 74 | ||
Line 120... | Line 121... | ||
120 | 121 | ||
121 | align 4 |
122 | align 4 |
122 | proc arp_table_manager stdcall uses ebx esi edi ecx edx,\ |
123 | proc arp_table_manager stdcall uses ebx esi edi ecx edx,\ |
Line 123... | Line 124... | ||
123 | Opcode:DWORD,Index:DWORD,Extra:DWORD |
124 | Opcode:DWORD,Index:DWORD,Extra:DWORD |
124 | 125 | ||
Line 125... | Line 126... | ||
125 | mov ebx, dword[ARPTable_ptr] ;ARPTable base |
126 | mov ebx, dword[ARPTable_ptr];ARPTable base |
126 | mov ecx, dword[NumARP] ;ARP-entries counter |
127 | mov ecx, dword[NumARP] ;ARP-entries counter |
127 | 128 | ||
128 | mov eax, dword[Opcode] |
129 | mov eax, dword[Opcode] |
129 | cmp eax, ARP_TABLE_TIMER |
130 | cmp eax, ARP_TABLE_TIMER |
130 | je .timer |
131 | je .timer |
131 | cmp eax, ARP_TABLE_ADD |
132 | cmp eax, ARP_TABLE_ADD |
132 | je .add |
133 | je .add |
133 | cmp eax, ARP_TABLE_DEL |
134 | cmp eax, ARP_TABLE_DEL |
134 | je .del |
135 | je .del |
135 | cmp eax, ARP_TABLE_GET |
136 | cmp eax, ARP_TABLE_GET |
136 | je .get |
137 | je .get |
137 | cmp eax, ARP_TABLE_IP_TO_MAC |
138 | cmp eax, ARP_TABLE_IP_TO_MAC |
138 | je .ip_to_mac |
139 | je .ip_to_mac |
Line 139... | Line 140... | ||
139 | cmp eax, ARP_TABLE_GET_ENTRIES_NUMBER |
140 | cmp eax, ARP_TABLE_GET_ENTRIES_NUMBER |
140 | je .get_entries_number |
141 | je .get_entries_number |
141 | jmp .exit ;if unknown opcode |
142 | jmp .exit ;if unknown opcode |
Line 148... | Line 149... | ||
148 | ;; Extra: must be zero |
149 | ;; Extra: must be zero |
149 | ;;OUT: |
150 | ;;OUT: |
150 | ;; EAX=not defined |
151 | ;; EAX=not defined |
151 | ;; |
152 | ;; |
152 | .timer: |
153 | .timer: |
153 | test ecx, ecx |
154 | test ecx, ecx |
154 | jz .exit ;if NumARP=0 nothing to do |
155 | jz .exit;if NumARP=0 nothing to do |
155 | sub ecx, ARP_TABLE_ENTRIES ;ecx=dynamic entries number |
156 | sub ecx, ARP_TABLE_ENTRIES;ecx=dynamic entries number |
156 | jz .exit ;if NumARP=number of static entries then exit |
157 | jz .exit;if NumARP=number of static entries then exit |
Line 157... | Line 158... | ||
157 | 158 | ||
Line 158... | Line 159... | ||
158 | add ebx, ARP_TABLE_ENTRIES*ARP_ENTRY_SIZE ;ebx=dynamic entries base |
159 | add ebx, ARP_TABLE_ENTRIES*ARP_ENTRY_SIZE;ebx=dynamic entries base |
159 | 160 | ||
160 | .timer_loop: |
161 | .timer_loop: |
161 | movsx esi, word [ebx + ARP_ENTRY.TTL] |
162 | movsx esi, word [ebx + ARP_ENTRY.TTL] |
Line 162... | Line 163... | ||
162 | cmp esi, 0xFFFFFFFF |
163 | cmp esi, 0xFFFFFFFF |
163 | je .timer_loop_end ;if TTL==0xFFFF then it's static entry |
164 | je .timer_loop_end;if TTL==0xFFFF then it's static entry |
Line 164... | Line 165... | ||
164 | 165 | ||
165 | test esi, esi |
166 | test esi, esi |
166 | jnz .timer_loop_end_with_dec ;if TTL!=0 |
167 | jnz .timer_loop_end_with_dec;if TTL!=0 |
167 | 168 | ||
168 | ; Ok, TTL is 0 |
169 | ; Ok, TTL is 0 |
Line 169... | Line 170... | ||
169 | ;if Status==AWAITING_RESPONSE and TTL==0 |
170 | ;if Status==AWAITING_RESPONSE and TTL==0 |
170 | ;then we have to change it to ARP_RESPONSE_TIMEOUT |
171 | ;then we have to change it to ARP_RESPONSE_TIMEOUT |
171 | cmp word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
172 | cmp word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
Line 172... | Line 173... | ||
172 | jne @f |
173 | jne @f |
173 | 174 | ||
174 | mov word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT |
175 | mov word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT |
175 | mov word [ebx + ARP_ENTRY.TTL], word 0x000A ;10 sec |
176 | mov word [ebx + ARP_ENTRY.TTL], word 0x000A;10 sec |
176 | jmp .timer_loop_end |
177 | jmp .timer_loop_end |
177 | 178 | ||
178 | @@: |
179 | @@: |
Line 179... | Line 180... | ||
179 | ;if TTL==0 and Status==VALID_MAPPING, we have to delete it |
180 | ;if TTL==0 and Status==VALID_MAPPING, we have to delete it |
180 | ;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too |
181 | ;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too |
181 | mov esi, dword[NumARP] |
182 | mov esi, dword[NumARP] |
182 | sub esi, ecx ;esi=index of entry, will be deleted |
183 | sub esi, ecx ;esi=index of entry, will be deleted |
183 | stdcall arp_table_manager,ARP_TABLE_DEL,esi,0 ;opcode,index,extra |
184 | stdcall arp_table_manager, ARP_TABLE_DEL, esi, 0;opcode,index,extra |
Line 184... | Line 185... | ||
184 | jmp .timer_loop_end |
185 | jmp .timer_loop_end |
185 | 186 | ||
Line 186... | Line 187... | ||
186 | 187 | ||
187 | .timer_loop_end_with_dec: |
188 | .timer_loop_end_with_dec: |
188 | dec word [ebx + ARP_ENTRY.TTL] ;decrease TTL |
189 | dec word [ebx + ARP_ENTRY.TTL];decrease TTL |
Line 204... | Line 205... | ||
204 | ;;OUT: |
205 | ;;OUT: |
205 | ;; EAX=index of entry, that has been added |
206 | ;; EAX=index of entry, that has been added |
206 | ;; |
207 | ;; |
207 | .add: |
208 | .add: |
Line 208... | Line 209... | ||
208 | 209 | ||
Line 209... | Line 210... | ||
209 | sub esp, ARP_ENTRY_SIZE ;Allocate ARP_ENTRY_SIZE byte in stack |
210 | sub esp, ARP_ENTRY_SIZE;Allocate ARP_ENTRY_SIZE byte in stack |
210 | 211 | ||
Line 211... | Line 212... | ||
211 | mov esi, [Extra] ;pointer |
212 | mov esi, [Extra];pointer |
212 | mov edi, [Index] ;opcode |
213 | mov edi, [Index];opcode |
213 | 214 | ||
Line 214... | Line 215... | ||
214 | cmp edi, EXTRA_IS_ARP_PACKET_PTR |
215 | cmp edi, EXTRA_IS_ARP_PACKET_PTR |
215 | je .arp_packet_to_entry ;if Extra contain ptr to ARP_PACKET and we have to form arp-entry |
216 | je .arp_packet_to_entry;if Extra contain ptr to ARP_PACKET and we have to form arp-entry |
216 | ;else it contain ptr to arp-entry |
217 | ;else it contain ptr to arp-entry |
217 | 218 | ||
218 | cld |
219 | cld |
219 | ; esi already has been loaded |
220 | ; esi already has been loaded |
Line 220... | Line 221... | ||
220 | mov edi, esp ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
221 | mov edi, esp ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
221 | mov ecx,ARP_ENTRY_SIZE/2 ;ARP_ENTRY_SIZE must be even number!!! |
222 | mov ecx, ARP_ENTRY_SIZE/2;ARP_ENTRY_SIZE must be even number!!! |
222 | rep movsw ;copy |
223 | rep movsw ;copy |
Line 223... | Line 224... | ||
223 | jmp .search |
224 | jmp .search |
224 | 225 | ||
225 | .arp_packet_to_entry: |
226 | .arp_packet_to_entry: |
226 | mov edx, dword[esi + ARP_PACKET.SenderIP] ;esi=base of ARP_PACKET |
227 | mov edx, dword[esi + ARP_PACKET.SenderIP];esi=base of ARP_PACKET |
227 | mov [esp + ARP_ENTRY.IP], edx |
228 | mov [esp + ARP_ENTRY.IP], edx |
228 | 229 | ||
229 | cld |
230 | cld |
Line 230... | Line 231... | ||
230 | lea esi, [esi + ARP_PACKET.SenderMAC] |
231 | lea esi, [esi + ARP_PACKET.SenderMAC] |
231 | lea edi, [esp + ARP_ENTRY.MAC] |
232 | lea edi, [esp + ARP_ENTRY.MAC] |
232 | movsd |
233 | movsd |
233 | movsw |
234 | movsw |
234 | mov word[esp + ARP_ENTRY.Status], ARP_VALID_MAPPING ; specify the type - a valid entry |
235 | mov word[esp + ARP_ENTRY.Status], ARP_VALID_MAPPING; specify the type - a valid entry |
235 | mov word[esp + ARP_ENTRY.TTL], 0x0E10 ; = 1 hour |
236 | mov word[esp + ARP_ENTRY.TTL], 0x0E10; = 1 hour |
236 | 237 | ||
237 | .search: |
238 | .search: |
238 | mov edx, dword[esp + ARP_ENTRY.IP] ;edx=IP-address, which we'll search |
239 | mov edx, dword[esp + ARP_ENTRY.IP];edx=IP-address, which we'll search |
239 | mov ecx, dword[NumARP] ;ecx=ARP-entries counter |
240 | mov ecx, dword[NumARP] ;ecx=ARP-entries counter |
Line 240... | Line 241... | ||
240 | jecxz .add_to_end ;if ARP-entries number == 0 |
241 | jecxz .add_to_end ;if ARP-entries number == 0 |
241 | imul eax, ecx, ARP_ENTRY_SIZE ;eax=current table size(in bytes) |
242 | imul eax, ecx, ARP_ENTRY_SIZE ;eax=current table size(in bytes) |
242 | @@: |
243 | @@: |
243 | sub eax, ARP_ENTRY_SIZE |
244 | sub eax, ARP_ENTRY_SIZE |
244 | cmp dword[ebx + eax + ARP_ENTRY.IP], edx |
245 | cmp dword[ebx + eax + ARP_ENTRY.IP], edx |
245 | loopnz @b |
246 | loopnz @b |
Line 246... | Line 247... | ||
246 | jz .replace ; found, replace existing entry, ptr to it is in eax |
247 | jz .replace ; found, replace existing entry, ptr to it is in eax |
247 | 248 | ||
Line 248... | Line 249... | ||
248 | .add_to_end: |
249 | .add_to_end: |
249 | ;else add to end |
250 | ;else add to end |
250 | or eax,-1 ;set eax=0xFFFFFFFF if adding is impossible |
251 | or eax, -1;set eax=0xFFFFFFFF if adding is impossible |
251 | mov ecx, dword[NumARP] |
252 | mov ecx, dword[NumARP] |
252 | cmp ecx, ARP_TABLE_SIZE |
253 | cmp ecx, ARP_TABLE_SIZE |
253 | je .add_exit ;if arp-entries number is equal to arp-table maxsize |
254 | je .add_exit;if arp-entries number is equal to arp-table maxsize |
254 | 255 | ||
255 | imul eax, dword[NumARP], ARP_ENTRY_SIZE ;eax=ptr to end of ARPTable |
256 | imul eax, dword[NumARP], ARP_ENTRY_SIZE;eax=ptr to end of ARPTable |
256 | inc dword [NumARP] ;increase ARP-entries counter |
257 | inc dword [NumARP];increase ARP-entries counter |
257 | 258 | ||
Line 258... | Line 259... | ||
258 | .replace: |
259 | .replace: |
259 | cld |
260 | cld |
260 | mov esi, esp ;esp=base of ARP-entry, that will be added |
261 | mov esi, esp ;esp=base of ARP-entry, that will be added |
261 | lea edi, [ebx + eax] ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
262 | lea edi, [ebx + eax] ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
Line 262... | Line 263... | ||
262 | mov ecx,ARP_ENTRY_SIZE/2 ;ARP_ENTRY_SIZE must be even number!!! |
263 | mov ecx, ARP_ENTRY_SIZE/2;ARP_ENTRY_SIZE must be even number!!! |
263 | rep movsw |
264 | rep movsw |
264 | 265 | ||
Line 278... | Line 279... | ||
278 | ;; Extra: must be zero |
279 | ;; Extra: must be zero |
279 | ;;OUT: |
280 | ;;OUT: |
280 | ;; EAX=not defined |
281 | ;; EAX=not defined |
281 | ;; |
282 | ;; |
282 | .del: |
283 | .del: |
283 | mov esi, [Index] |
284 | mov esi, [Index] |
284 | imul esi, ARP_ENTRY_SIZE |
285 | imul esi, ARP_ENTRY_SIZE |
Line 285... | Line 286... | ||
285 | 286 | ||
286 | mov ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY_SIZE |
287 | mov ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY_SIZE |
Line 287... | Line 288... | ||
287 | sub ecx, esi |
288 | sub ecx, esi |
288 | 289 | ||
Line 289... | Line 290... | ||
289 | lea edi, [ebx + esi] ;edi=ptr to entry that should be deleted |
290 | lea edi, [ebx + esi] ;edi=ptr to entry that should be deleted |
290 | lea esi, [edi + ARP_ENTRY_SIZE] ;esi=ptr to next entry |
291 | lea esi, [edi + ARP_ENTRY_SIZE];esi=ptr to next entry |
291 | 292 | ||
Line 292... | Line 293... | ||
292 | shr ecx,1 ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER! |
293 | shr ecx, 1 ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER! |
293 | cld |
294 | cld |
294 | rep movsw |
295 | rep movsw |
Line 295... | Line 296... | ||
295 | 296 | ||
296 | dec dword[NumARP] ;decrease arp-entries counter |
297 | dec dword[NumARP];decrease arp-entries counter |
297 | jmp .exit |
298 | jmp .exit |
Line 304... | Line 305... | ||
304 | ;; Extra: pointer to buffer for reading(size must be equal to ARP_ENTRY_SIZE) |
305 | ;; Extra: pointer to buffer for reading(size must be equal to ARP_ENTRY_SIZE) |
305 | ;;OUT: |
306 | ;;OUT: |
306 | ;; EAX=not defined |
307 | ;; EAX=not defined |
307 | ;; |
308 | ;; |
308 | .get: |
309 | .get: |
309 | mov esi, [Index] |
310 | mov esi, [Index] |
310 | imul esi, ARP_ENTRY_SIZE ;esi=ptr to required ARP_ENTRY |
311 | imul esi, ARP_ENTRY_SIZE;esi=ptr to required ARP_ENTRY |
311 | mov edi, [Extra] ;edi=buffer for reading |
312 | mov edi, [Extra] ;edi=buffer for reading |
312 | mov ecx, ARP_ENTRY_SIZE/2 ; must be even number!!! |
313 | mov ecx, ARP_ENTRY_SIZE/2; must be even number!!! |
313 | cld |
314 | cld |
314 | rep movsw |
315 | rep movsw |
315 | jmp .exit |
316 | jmp .exit |
316 | ;;END GET |
317 | ;;END GET |
Line 317... | Line 318... | ||
317 | 318 | ||
318 | ;;BEGIN IP_TO_MAC |
319 | ;;BEGIN IP_TO_MAC |
319 | ;;Description: it gets an IP from Index, scans each entry in the table and writes |
320 | ;;Description: it gets an IP from Index, scans each entry in the table and writes |
Line 333... | Line 334... | ||
333 | ;; resolved, or that doesn't exist. I recommend you, to do at most 3-5 calls of this |
334 | ;; resolved, or that doesn't exist. I recommend you, to do at most 3-5 calls of this |
334 | ;; function with 1sec delay. sure, only if it not return a valid MAC after a first call. |
335 | ;; function with 1sec delay. sure, only if it not return a valid MAC after a first call. |
335 | ;; |
336 | ;; |
336 | .ip_to_mac: |
337 | .ip_to_mac: |
Line 337... | Line 338... | ||
337 | 338 | ||
338 | xor eax, eax |
339 | xor eax, eax |
339 | mov edi, dword[Extra] |
340 | mov edi, dword[Extra] |
340 | cld |
341 | cld |
341 | stosd |
342 | stosd |
Line 342... | Line 343... | ||
342 | stosw |
343 | stosw |
343 | 344 | ||
344 | 345 | ||
345 | ; first, check destination IP to see if it is on 'this' network. |
346 | ; first, check destination IP to see if it is on 'this' network. |
346 | ; The test is: |
347 | ; The test is: |
347 | ; if ( destIP & subnet_mask == stack_ip & subnet_mask ) |
348 | ; if ( destIP & subnet_mask == stack_ip & subnet_mask ) |
Line 348... | Line 349... | ||
348 | ; destination is local |
349 | ; destination is local |
349 | ; else |
350 | ; else |
350 | ; destination is remote, so pass to gateway |
351 | ; destination is remote, so pass to gateway |
351 | 352 | ||
352 | mov eax, [Index] ;eax=required IP |
353 | mov eax, [Index] ;eax=required IP |
353 | mov esi, eax |
354 | mov esi, eax |
354 | and esi, [subnet_mask] |
355 | and esi, [subnet_mask] |
355 | mov ecx, [stack_ip] |
356 | mov ecx, [stack_ip] |
356 | and ecx, [subnet_mask] |
357 | and ecx, [subnet_mask] |
357 | cmp esi, ecx |
358 | cmp esi, ecx |
Line 358... | Line 359... | ||
358 | je @f ;if we and target IP are located in the same network |
359 | je @f ;if we and target IP are located in the same network |
359 | mov eax, [gateway_ip] |
360 | mov eax, [gateway_ip] |
360 | mov [Index], eax |
361 | mov [Index], eax |
Line 361... | Line 362... | ||
361 | @@: |
362 | @@: |
362 | 363 | ||
Line 363... | Line 364... | ||
363 | cmp dword[NumARP], 0 |
364 | cmp dword[NumARP], 0 |
364 | je .ip_to_mac_send_request ;if ARP-table not contain an entries, we have to request IP. |
365 | je .ip_to_mac_send_request;if ARP-table not contain an entries, we have to request IP. |
365 | ;EAX will be containing a zero, it's equal to ARP_NO_ENTRY |
366 | ;EAX will be containing a zero, it's equal to ARP_NO_ENTRY |
366 | 367 | ||
367 | mov ecx, dword[NumARP] |
368 | mov ecx, dword[NumARP] |
Line 368... | Line 369... | ||
368 | imul esi, ecx, ARP_ENTRY_SIZE ;esi=current ARP-table size |
369 | imul esi, ecx, ARP_ENTRY_SIZE;esi=current ARP-table size |
369 | 370 | ||
Line 370... | Line 371... | ||
370 | @@: |
371 | @@: |
371 | sub esi, ARP_ENTRY_SIZE |
372 | sub esi, ARP_ENTRY_SIZE |
372 | cmp [ebx + esi], eax ; ebx=ARPTable base |
373 | cmp [ebx + esi], eax ; ebx=ARPTable base |
373 | loopnz @b ; Return back if non match |
374 | loopnz @b ; Return back if non match |
374 | jnz .ip_to_mac_send_request ; and request IP->MAC if none found in the table |
375 | jnz .ip_to_mac_send_request; and request IP->MAC if none found in the table |
375 | 376 | ||
376 | ; Return the entry status in eax |
377 | ; Return the entry status in eax |
Line 377... | Line 378... | ||
377 | movzx eax, word[ebx + esi + ARP_ENTRY.Status] |
378 | movzx eax, word[ebx + esi + ARP_ENTRY.Status] |
378 | 379 | ||
379 | ; esi holds index |
380 | ; esi holds index |
380 | cld |
381 | cld |
Line 381... | Line 382... | ||
381 | lea esi, [ebx + esi + ARP_ENTRY.MAC] |
382 | lea esi, [ebx + esi + ARP_ENTRY.MAC] |
Line 382... | Line 383... | ||
382 | mov edi, [Extra] ;edi=ptr to buffer for write MAC |
383 | mov edi, [Extra];edi=ptr to buffer for write MAC |
383 | movsd |
384 | movsd |
Line 397... | Line 398... | ||
397 | ;; Index: must be zero |
398 | ;; Index: must be zero |
398 | ;; Extra: must be zero |
399 | ;; Extra: must be zero |
399 | ;;OUT: |
400 | ;;OUT: |
400 | ;; EAX=ARP-entries number in the ARPTable |
401 | ;; EAX=ARP-entries number in the ARPTable |
401 | .get_entries_number: |
402 | .get_entries_number: |
402 | mov eax, dword[NumARP] |
403 | mov eax, dword[NumARP] |
403 | jmp .exit |
404 | jmp .exit |
404 | ;;END GET_ENTRIES_NUMBER |
405 | ;;END GET_ENTRIES_NUMBER |
Line 405... | Line 406... | ||
405 | 406 | ||
406 | .exit: |
407 | .exit: |
407 | ret |
408 | ret |
Line 408... | Line 409... | ||
408 | endp |
409 | endp |
409 | 410 | ||
Line 426... | Line 427... | ||
426 | ; Is this a REQUEST? |
427 | ; Is this a REQUEST? |
427 | ; Is this a request for My Host IP |
428 | ; Is this a request for My Host IP |
428 | ; Yes - So construct a response message. |
429 | ; Yes - So construct a response message. |
429 | ; Send this message to the ethernet card for transmission |
430 | ; Send this message to the ethernet card for transmission |
Line 430... | Line 431... | ||
430 | 431 | ||
Line 431... | Line 432... | ||
431 | stdcall arp_table_manager,ARP_TABLE_ADD,EXTRA_IS_ARP_PACKET_PTR,ETH_FRAME.Data + ARP_PACKET |
432 | stdcall arp_table_manager, ARP_TABLE_ADD, EXTRA_IS_ARP_PACKET_PTR, ETH_FRAME.Data + ARP_PACKET |
Line 432... | Line 433... | ||
432 | 433 | ||
433 | inc dword[arp_rx_count] ;increase ARP-packets counter |
434 | inc dword[arp_rx_count];increase ARP-packets counter |
Line 434... | Line 435... | ||
434 | 435 | ||
435 | cmp word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REQ_OPCODE ; Is this a request packet? |
436 | cmp word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REQ_OPCODE; Is this a request packet? |
436 | jne .exit ; No - so exit |
437 | jne .exit ; No - so exit |
Line 437... | Line 438... | ||
437 | 438 | ||
438 | mov eax, [stack_ip] |
439 | mov eax, [stack_ip] |
Line 439... | Line 440... | ||
439 | cmp eax, dword[ETH_FRAME.Data + ARP_PACKET.TargetIP] ; Is it looking for my IP address? |
440 | cmp eax, dword[ETH_FRAME.Data + ARP_PACKET.TargetIP] ; Is it looking for my IP address? |
Line 440... | Line 441... | ||
440 | jne .exit ; No - so quit now |
441 | jne .exit ; No - so quit now |
441 | 442 | ||
442 | ; OK, it is a request for my MAC address. Build the frame and send it |
443 | ; OK, it is a request for my MAC address. Build the frame and send it |
443 | ; We can reuse the packet. |
444 | ; We can reuse the packet. |
444 | 445 | ||
445 | mov word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REP_OPCODE |
446 | mov word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REP_OPCODE |
446 | 447 | ||
447 | cld |
448 | cld |
448 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
449 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
449 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC |
450 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC |
450 | movsd |
451 | movsd |
451 | movsw |
452 | movsw |
452 | 453 | ||
453 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
454 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
454 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetIP |
455 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetIP |
455 | movsd |
456 | movsd |
456 | 457 | ||
457 | mov esi, node_addr |
458 | mov esi, node_addr |
Line 458... | Line 459... | ||
458 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
459 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
459 | movsd |
460 | movsd |
460 | movsw |
461 | movsw |
461 | 462 | ||
462 | mov esi, stack_ip |
463 | mov esi, stack_ip |
463 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
464 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
464 | movsd |
465 | movsd |
465 | 466 | ||
Line 466... | Line 467... | ||
466 | ; Now, send it! |
467 | ; Now, send it! |
467 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC ;ptr to destination MAC address |
468 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC;ptr to destination MAC address |
Line 468... | Line 469... | ||
468 | mov bx, ETHER_ARP ;type of protocol |
469 | mov bx, ETHER_ARP ;type of protocol |
469 | mov ecx, 28 ;data size |
470 | mov ecx, 28 ;data size |
470 | mov esi, ETH_FRAME.Data + ARP_PACKET ;ptr to data |
471 | mov esi, ETH_FRAME.Data + ARP_PACKET ;ptr to data |
Line 493... | Line 494... | ||
493 | ; |
494 | ; |
494 | ;*************************************************************************** |
495 | ;*************************************************************************** |
495 | proc arp_request stdcall uses ebx esi edi,\ |
496 | proc arp_request stdcall uses ebx esi edi,\ |
496 | TargetIP:DWORD, SenderIP_ptr:DWORD, SenderMAC_ptr:DWORD |
497 | TargetIP:DWORD, SenderIP_ptr:DWORD, SenderMAC_ptr:DWORD |
Line 497... | Line 498... | ||
497 | 498 | ||
Line 498... | Line 499... | ||
498 | inc dword[arp_tx_count] ; increase counter |
499 | inc dword[arp_tx_count]; increase counter |
Line 499... | Line 500... | ||
499 | 500 | ||
500 | sub esp, 28 ; allocate memory for ARP_PACKET |
501 | sub esp, 28; allocate memory for ARP_PACKET |
501 | 502 | ||
502 | mov word[esp + ARP_PACKET.HardwareType],0x0100 ;Ethernet |
503 | mov word[esp + ARP_PACKET.HardwareType], 0x0100;Ethernet |
503 | mov word[esp + ARP_PACKET.ProtocolType],0x0008 ;IP |
504 | mov word[esp + ARP_PACKET.ProtocolType], 0x0008;IP |
504 | mov byte[esp + ARP_PACKET.HardwareSize],0x06 ;MAC-addr length |
505 | mov byte[esp + ARP_PACKET.HardwareSize], 0x06;MAC-addr length |
505 | mov byte[esp + ARP_PACKET.ProtocolSize],0x04 ;IP-addr length |
506 | mov byte[esp + ARP_PACKET.ProtocolSize], 0x04;IP-addr length |
506 | mov word[esp + ARP_PACKET.Opcode],0x0100 ;Request |
507 | mov word[esp + ARP_PACKET.Opcode], 0x0100 ;Request |
507 | 508 | ||
508 | cld |
509 | cld |
509 | mov esi,[SenderMAC_ptr] |
510 | mov esi, [SenderMAC_ptr] |
510 | lea edi,[esp + ARP_PACKET.SenderMAC] ;Our MAC-addr |
511 | lea edi, [esp + ARP_PACKET.SenderMAC] ;Our MAC-addr |
511 | movsd |
512 | movsd |
512 | movsw |
513 | movsw |
513 | 514 | ||
514 | mov esi,[SenderIP_ptr] |
515 | mov esi, [SenderIP_ptr] |
515 | lea edi,[esp + ARP_PACKET.SenderIP] ;Our IP-addr |
516 | lea edi, [esp + ARP_PACKET.SenderIP] ;Our IP-addr |
516 | movsd |
517 | movsd |
517 | 518 | ||
518 | xor eax, eax |
519 | xor eax, eax |
Line 519... | Line 520... | ||
519 | lea edi, [esp + ARP_PACKET.TargetMAC] ;Required MAC-addr(zeroed) |
520 | lea edi, [esp + ARP_PACKET.TargetMAC] ;Required MAC-addr(zeroed) |
520 | stosd |
521 | stosd |
Line 521... | Line 522... | ||
521 | stosw |
522 | stosw |
522 | 523 | ||
523 | mov esi, dword[TargetIP] |
524 | mov esi, dword[TargetIP] |
524 | mov dword[esp + ARP_PACKET.TargetIP],esi ;Required IP-addr(we get it as function parameter) |
525 | mov dword[esp + ARP_PACKET.TargetIP], esi;Required IP-addr(we get it as function parameter) |
525 | 526 | ||
526 | ; Now, send it! |
527 | ; Now, send it! |
527 | mov edi, broadcast_add ; Pointer to 48 bit destination address |
528 | mov edi, broadcast_add ; Pointer to 48 bit destination address |
528 | mov bx, ETHER_ARP ; Type of packet |
529 | mov bx, ETHER_ARP ; Type of packet |
Line 529... | Line 530... | ||
529 | mov ecx, 28 ; size of packet |
530 | mov ecx, 28 ; size of packet |
Line 530... | Line 531... | ||
530 | lea esi, [esp + ARP_PACKET]; pointer to packet data |
531 | lea esi, [esp + ARP_PACKET]; pointer to packet data |
531 | push ebp |
532 | push ebp |
Line 532... | Line 533... | ||
532 | call dword [drvr_transmit] ; Call the drivers transmit function |
533 | call dword [drvr_transmit]; Call the drivers transmit function |
533 | pop ebp |
534 | pop ebp |
Line 534... | Line 535... | ||
534 | 535 | ||
535 | add esp, 28 ; free memory, allocated before for ARP_PACKET |
536 | add esp, 28; free memory, allocated before for ARP_PACKET |
536 | 537 | ||
537 | ; Add an entry in the ARP table, awaiting response |
538 | ; Add an entry in the ARP table, awaiting response |
Line 538... | Line 539... | ||
538 | sub esp, ARP_ENTRY_SIZE ;allocate memory for ARP-entry |
539 | sub esp, ARP_ENTRY_SIZE;allocate memory for ARP-entry |
539 | 540 | ||
Line 540... | Line 541... | ||
540 | mov esi, dword[TargetIP] |
541 | mov esi, dword[TargetIP] |
541 | mov dword[esp + ARP_ENTRY.IP],esi |
542 | mov dword[esp + ARP_ENTRY.IP], esi |
Line 542... | Line 543... | ||
542 | 543 | ||
543 | lea edi, [esp + ARP_ENTRY.MAC] |
544 | lea edi, [esp + ARP_ENTRY.MAC] |
544 | xor eax, eax |
545 | xor eax, eax |