Rev 5522 | Rev 7535 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5522 | Rev 6011 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
15 | ;; Version 2, June- 1991 ;; |
15 | ;; Version 2, June- 1991 ;; |
16 | ;; ;; |
16 | ;; ;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 18... | Line 18... | ||
18 | 18 | ||
Line 19... | Line 19... | ||
19 | $Revision: 5522 $ |
19 | $Revision: 6011 $ |
20 | 20 | ||
21 | ARP_NO_ENTRY = 0 |
21 | ARP_NO_ENTRY = 0 |
22 | ARP_VALID_MAPPING = 1 |
22 | ARP_VALID_MAPPING = 1 |
Line 68... | Line 68... | ||
68 | 68 | ||
Line 69... | Line 69... | ||
69 | endg |
69 | endg |
70 | - | ||
71 | - | ||
72 | - | ||
- | 70 | ||
73 | ;----------------------------------------------------------------- |
71 | |
74 | ; |
- | |
- | 72 | ||
75 | ; ARP_init |
73 | ;-----------------------------------------------------------------; |
76 | ; |
74 | ; ; |
Line 77... | Line 75... | ||
77 | ; This function resets all ARP variables |
75 | ; arp_init: Resets all ARP variables. ; |
78 | ; |
76 | ; ; |
79 | ;----------------------------------------------------------------- |
77 | ;-----------------------------------------------------------------; |
80 | macro ARP_init { |
78 | macro arp_init { |
Line 81... | Line 79... | ||
81 | 79 | ||
Line 82... | Line 80... | ||
82 | xor eax, eax |
80 | xor eax, eax |
83 | mov edi, ARP_entries_num |
- | |
- | 81 | mov edi, ARP_entries_num |
|
84 | mov ecx, 4*NET_DEVICES_MAX |
82 | mov ecx, 4*NET_DEVICES_MAX |
85 | rep stosd |
- | |
- | 83 | rep stosd |
|
86 | 84 | ||
87 | } |
- | |
88 | 85 | } |
|
Line 89... | Line 86... | ||
89 | ;--------------------------------------------------------------------------- |
86 | |
90 | ; |
87 | ;-----------------------------------------------------------------; |
Line 91... | Line 88... | ||
91 | ; ARP_decrease_entry_ttls |
88 | ; ; |
Line 133... | Line 130... | ||
133 | .time_out: |
130 | .time_out: |
134 | cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE |
131 | cmp [esi + ARP_entry.Status], ARP_AWAITING_RESPONSE |
135 | je .response_timeout |
132 | je .response_timeout |
Line 136... | Line 133... | ||
136 | 133 | ||
137 | push esi edi ecx |
134 | push esi edi ecx |
138 | call ARP_del_entry |
135 | call arp_del_entry |
Line 139... | Line 136... | ||
139 | pop ecx edi esi |
136 | pop ecx edi esi |
Line 140... | Line 137... | ||
140 | 137 | ||
Line 152... | Line 149... | ||
152 | jb .loop_outer |
149 | jb .loop_outer |
Line 153... | Line 150... | ||
153 | 150 | ||
Line 154... | Line 151... | ||
154 | } |
151 | } |
155 | - | ||
- | 152 | ||
156 | 153 | ||
157 | ;----------------------------------------------------------------- |
- | |
- | 154 | ;-----------------------------------------------------------------; |
|
158 | ; |
155 | ; ; |
159 | ; ARP_input |
156 | ; arp_input ; |
160 | ; |
157 | ; ; |
161 | ; IN: Pointer to buffer in [esp] |
158 | ; IN: [esp] = Pointer to buffer ; |
162 | ; size of buffer in [esp+4] |
159 | ; [esp+4] = size of buffer ; |
- | 160 | ; ecx = packet size (without ethernet header) ; |
|
163 | ; packet size (without ethernet header) in ecx |
161 | ; edx = packet ptr ; |
164 | ; packet ptr in edx |
- | |
- | 162 | ; ebx = device ptr ; |
|
165 | ; device ptr in ebx |
163 | ; ; |
166 | ; OUT: / |
164 | ; OUT: / ; |
167 | ; |
165 | ; ; |
Line 168... | Line 166... | ||
168 | ;----------------------------------------------------------------- |
166 | ;-----------------------------------------------------------------; |
169 | align 4 |
167 | align 4 |
Line 170... | Line 168... | ||
170 | ARP_input: |
168 | arp_input: |
171 | 169 | ||
Line 172... | Line 170... | ||
172 | ;----------------------------------------- |
170 | ;----------------------------------------- |
173 | ; Check validity and print some debug info |
171 | ; Check validity and print some debug info |
174 | 172 | ||
Line 175... | Line 173... | ||
175 | cmp ecx, sizeof.ARP_header |
173 | cmp ecx, sizeof.ARP_header |
Line 292... | Line 290... | ||
292 | inc [ARP_CONFLICTS + edi] |
290 | inc [ARP_CONFLICTS + edi] |
293 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n" |
291 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n" |
Line 294... | Line 292... | ||
294 | 292 | ||
295 | .exit: |
293 | .exit: |
296 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: exiting\n" |
294 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: exiting\n" |
297 | call NET_BUFF_free |
295 | call net_buff_free |
Line 298... | Line 296... | ||
298 | ret |
296 | ret |
299 | - | ||
- | 297 | ||
300 | ;--------------------------------------------------------------------------- |
298 | ;-----------------------------------------------------------------; |
301 | ; |
- | |
- | 299 | ; ; |
|
302 | ; ARP_output_request |
300 | ; arp_output_request ; |
303 | ; |
301 | ; ; |
304 | ; IN: ebx = device ptr |
- | |
- | 302 | ; IN: ebx = device ptr ; |
|
305 | ; eax = IP |
303 | ; eax = IP ; |
306 | ; OUT: / |
- | |
- | 304 | ; ; |
|
307 | ; scratched: probably everything |
305 | ; OUT: scratched: probably everything ; |
308 | ; |
306 | ; ; |
309 | ;--------------------------------------------------------------------------- |
307 | ;-----------------------------------------------------------------; |
Line 310... | Line 308... | ||
310 | align 4 |
308 | align 4 |
Line 311... | Line 309... | ||
311 | ARP_output_request: |
309 | arp_output_request: |
312 | 310 | ||
Line 313... | Line 311... | ||
313 | push eax |
311 | push eax |
314 | 312 | ||
315 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\ |
313 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\ |
316 | [esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx |
314 | [esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx |
317 | 315 | ||
Line 318... | Line 316... | ||
318 | mov ax, ETHER_PROTO_ARP |
316 | mov ax, ETHER_PROTO_ARP |
319 | mov ecx, sizeof.ARP_header |
317 | mov ecx, sizeof.ARP_header |
320 | mov edx, ETH_BROADCAST ; broadcast mac |
318 | mov edx, ETH_BROADCAST ; broadcast mac |
Line 331... | Line 329... | ||
331 | lea esi, [ebx + ETH_DEVICE.mac] ; SenderMac |
329 | lea esi, [ebx + ETH_DEVICE.mac] ; SenderMac |
332 | movsw ; |
330 | movsw ; |
333 | movsd ; |
331 | movsd ; |
Line 334... | Line 332... | ||
334 | 332 | ||
335 | push edi |
333 | push edi |
336 | call NET_ptr_to_num4 |
334 | call net_ptr_to_num4 |
337 | inc [ARP_PACKETS_TX + edi] ; assume we will succeed |
335 | inc [ARP_PACKETS_TX + edi] ; assume we will succeed |
338 | lea esi, [IP_LIST + edi] ; SenderIP |
336 | lea esi, [IP_LIST + edi] ; SenderIP |
339 | pop edi |
337 | pop edi |
Line 352... | Line 350... | ||
352 | add esp, 4 |
350 | add esp, 4 |
353 | DEBUGF DEBUG_NETWORK_ERROR, "ARP_output_request: send failed\n" |
351 | DEBUGF DEBUG_NETWORK_ERROR, "ARP_output_request: send failed\n" |
354 | ret |
352 | ret |
Line 355... | Line 353... | ||
355 | 353 | ||
356 | - | ||
- | 354 | ||
357 | ;----------------------------------------------------------------- |
355 | ;-----------------------------------------------------------------; |
358 | ; |
- | |
- | 356 | ; ; |
|
359 | ; ARP_add_entry (or update) |
357 | ; arp_add_entry: Add or update an entry in the ARP table. ; |
360 | ; |
358 | ; ; |
- | 359 | ; IN: esi = ptr to entry (can easily be made on the stack) ; |
|
361 | ; IN: esi = ptr to entry (can easily be made on the stack) |
360 | ; edi = device num*4 ; |
- | 361 | ; ; |
|
362 | ; edi = device num*4 |
362 | ; OUT: eax = entry number on success ; |
363 | ; OUT: eax = entry #, -1 on error |
- | |
- | 363 | ; eax = -1 on error ; |
|
364 | ; esi = ptr to newly created entry |
364 | ; esi = ptr to newly created entry ; |
365 | ; |
365 | ; ; |
366 | ;----------------------------------------------------------------- ; TODO: use a mutex |
366 | ;-----------------------------------------------------------------; |
- | 367 | align 4 |
|
- | 368 | arp_add_entry: |
|
Line 367... | Line 369... | ||
367 | align 4 |
369 | |
Line 368... | Line 370... | ||
368 | ARP_add_entry: |
370 | ; TODO: use a mutex to lock ARP table |
369 | 371 | ||
Line 419... | Line 421... | ||
419 | .full: |
421 | .full: |
420 | mov eax, -1 |
422 | mov eax, -1 |
421 | ret |
423 | ret |
Line 422... | Line 424... | ||
422 | 424 | ||
423 | - | ||
- | 425 | ||
424 | ;----------------------------------------------------------------- |
426 | ;-----------------------------------------------------------------; |
425 | ; |
- | |
- | 427 | ; ; |
|
426 | ; ARP_del_entry |
428 | ; arp_del_entry: Remove an entry from the ARP table. ; |
427 | ; |
429 | ; ; |
- | 430 | ; IN: esi = ptr to arp entry ; |
|
428 | ; IN: esi = ptr to arp entry |
431 | ; edi = device number ; |
429 | ; edi = device number |
- | |
- | 432 | ; ; |
|
430 | ; OUT: / |
433 | ; OUT: / ; |
431 | ; |
434 | ; ; |
432 | ;----------------------------------------------------------------- |
435 | ;-----------------------------------------------------------------; |
- | 436 | align 4 |
|
- | 437 | arp_del_entry: |
|
Line 433... | Line 438... | ||
433 | align 4 |
438 | |
434 | ARP_del_entry: |
439 | ; TODO: use a mutex to lock ARP table |
435 | 440 | ||
Line 436... | Line 441... | ||
436 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: entry=%x entrys=%u\n", esi, [ARP_entries_num + 4*edi] |
441 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: entry=0x%x entrys=%u\n", esi, [ARP_entries_num + 4*edi] |
437 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: IP=%u.%u.%u.%u\n", \ |
442 | DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_del_entry: IP=%u.%u.%u.%u\n", \ |
Line 461... | Line 466... | ||
461 | 466 | ||
462 | - | ||
463 | 467 | ||
464 | - | ||
465 | 468 | ||
466 | ;----------------------------------------------------------------- |
- | |
- | 469 | ||
467 | ; |
470 | |
468 | ; ARP_IP_to_MAC |
471 | ;-----------------------------------------------------------------; |
- | 472 | ; ; |
|
469 | ; |
473 | ; arp_ip_to_mac: Translate an IP address to a MAC address. ; |
- | 474 | ; ; |
|
470 | ; This function translates an IP address to a MAC address |
475 | ; IN: eax = IPv4 address ; |
471 | ; |
476 | ; edi = device number * 4 ; |
472 | ; IN: eax = IPv4 address |
477 | ; ; |
473 | ; edi = device number * 4 |
- | |
- | 478 | ; OUT: eax = -1 on error ; |
|
474 | ; OUT: eax = -1 on error, -2 means request send |
479 | ; eax = -2 when request send ; |
475 | ; else, ax = first two bytes of mac (high 16 bits of eax will be 0) |
480 | ; eax = first two bytes of mac on success ; |
476 | ; ebx = last four bytes of mac |
481 | ; ebx = last four bytes of mac on success ; |
Line 477... | Line 482... | ||
477 | ; edi = unchanged |
482 | ; edi = unchanged ; |
478 | ; |
483 | ; ; |
479 | ;----------------------------------------------------------------- |
484 | ;-----------------------------------------------------------------; |
480 | align 4 |
485 | align 4 |
Line 511... | Line 516... | ||
511 | ; Now craft the ARP entry on the stack |
516 | ; Now craft the ARP entry on the stack |
512 | pushw ARP_REQUEST_TTL ; TTL |
517 | pushw ARP_REQUEST_TTL ; TTL |
513 | pushw ARP_AWAITING_RESPONSE ; status |
518 | pushw ARP_AWAITING_RESPONSE ; status |
514 | pushd 0 ; mac |
519 | pushd 0 ; mac |
515 | pushw 0 |
520 | pushw 0 |
516 | pushd eax ; ip |
521 | pushd eax ; IP |
517 | mov esi, esp |
522 | mov esi, esp |
Line 518... | Line 523... | ||
518 | 523 | ||
519 | ; Add it to the list |
524 | ; Add it to the list |
Line 520... | Line 525... | ||
520 | call ARP_add_entry |
525 | call arp_add_entry |
521 | 526 | ||
Line 522... | Line 527... | ||
522 | ; Delete the temporary entry |
527 | ; Delete the temporary entry |
Line 532... | Line 537... | ||
532 | ; Now send a request packet on the network |
537 | ; Now send a request packet on the network |
533 | pop edi eax ; IP in eax, device number in ebx, for ARP_output_request |
538 | pop edi eax ; IP in eax, device number in ebx, for ARP_output_request |
Line 534... | Line 539... | ||
534 | 539 | ||
535 | push esi edi |
540 | push esi edi |
536 | mov ebx, [NET_DRV_LIST + edi] |
541 | mov ebx, [NET_DRV_LIST + edi] |
537 | call ARP_output_request |
542 | call arp_output_request |
538 | pop edi esi |
543 | pop edi esi |
539 | .found_it: |
544 | .found_it: |
540 | cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING ; Does it have a MAC assigned? |
545 | cmp [esi + ARP_entry.Status], ARP_VALID_MAPPING ; Does it have a MAC assigned? |
Line 574... | Line 579... | ||
574 | mov eax, 0x0000ffff |
579 | mov eax, 0x0000ffff |
575 | mov ebx, 0xffffffff |
580 | mov ebx, 0xffffffff |
576 | ret |
581 | ret |
Line 577... | Line 582... | ||
577 | 582 | ||
578 | - | ||
579 | ;----------------------------------------------------------------- |
- | |
580 | ; |
- | |
- | 583 | ||
581 | ; ARP_API |
584 | ;-----------------------------------------------------------------; |
582 | ; |
- | |
- | 585 | ; ; |
|
583 | ; This function is called by system function 76 |
586 | ; arp_api: Part of system function 76. ; |
584 | ; |
587 | ; ; |
585 | ; IN: subfunction number in bl |
588 | ; IN: bl = subfunction number ; |
586 | ; device number in bh |
- | |
- | 589 | ; bh = device number ; |
|
587 | ; ecx, edx, .. depends on subfunction |
590 | ; ecx, edx, .. depends on subfunction ; |
588 | ; |
- | |
- | 591 | ; ; |
|
589 | ; OUT: ? |
592 | ; OUT: depends on subfunction ; |
590 | ; |
593 | ; ; |
591 | ;----------------------------------------------------------------- |
594 | ;-----------------------------------------------------------------; |
Line 592... | Line 595... | ||
592 | align 4 |
595 | align 4 |
593 | ARP_api: |
596 | arp_api: |
Line 594... | Line 597... | ||
594 | 597 | ||
Line 648... | Line 651... | ||
648 | ret |
651 | ret |
Line 649... | Line 652... | ||
649 | 652 | ||
650 | .write: |
653 | .write: |
651 | ; esi = pointer to buffer |
654 | ; esi = pointer to buffer |
652 | mov edi, eax |
655 | mov edi, eax |
653 | call ARP_add_entry ; out: eax = entry number, -1 on error |
656 | call arp_add_entry ; out: eax = entry number, -1 on error |
Line 654... | Line 657... | ||
654 | ret |
657 | ret |
655 | 658 | ||
656 | .remove: |
659 | .remove: |
657 | ; ecx = # entry |
660 | ; ecx = # entry |
658 | cmp ecx, [ARP_entries_num + eax] |
661 | cmp ecx, [ARP_entries_num + eax] |
659 | jae .error |
662 | jae .error |
660 | imul ecx, sizeof.ARP_entry |
663 | imul ecx, sizeof.ARP_entry |
661 | lea esi, [ARP_table + ecx] |
664 | lea esi, [ARP_table + ecx] |
662 | mov edi, eax |
665 | mov edi, eax |
663 | shr edi, 2 |
666 | shr edi, 2 |
Line 664... | Line 667... | ||
664 | call ARP_del_entry |
667 | call arp_del_entry |
665 | ret |
668 | ret |
666 | 669 | ||
667 | .send_announce: |
670 | .send_announce: |
668 | mov ebx, [NET_DRV_LIST + eax] |
671 | mov ebx, [NET_DRV_LIST + eax] |