Rev 387 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 387 | Rev 444 | ||
---|---|---|---|
- | 1 | $Revision: 431 $ |
|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; |
- | |
- | 3 | ;; ;; |
|
- | 4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
|
- | 5 | ;; Distributed under terms of the GNU General Public License ;; |
|
- | 6 | ;; ;; |
|
3 | ;; ARP.INC |
7 | ;; ARP.INC ;; |
4 | ;; |
- | |
- | 8 | ;; ;; |
|
5 | ;; Address Resolution Protocol |
9 | ;; Address Resolution Protocol ;; |
6 | ;; |
- | |
- | 10 | ;; ;; |
|
7 | ;; Last revision: 10.11.2006 |
11 | ;; Last revision: 10.11.2006 ;; |
8 | ;; |
- | |
- | 12 | ;; ;; |
|
9 | ;; This file contains the following: |
13 | ;; This file contains the following: ;; |
10 | ;; arp_table_manager - Manages an ARPTable |
14 | ;; arp_table_manager - Manages an ARPTable ;; |
11 | ;; arp_request - Sends an ARP request on the ethernet |
15 | ;; arp_request - Sends an ARP request on the ethernet ;; |
12 | ;; arp_handler - Called when an ARP packet is received |
16 | ;; arp_handler - Called when an ARP packet is received ;; |
13 | ;; |
- | |
- | 17 | ;; ;; |
|
14 | ;; Changes history: |
18 | ;; Changes history: ;; |
15 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net |
19 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
16 | ;; 11.11.2006 - [Johnny_B] and [smb] |
20 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
17 | ;; |
- | |
- | 21 | ;; ;; |
|
18 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19 | 23 | ||
20 | ARP_NO_ENTRY equ 0 |
24 | ARP_NO_ENTRY equ 0 |
21 | ARP_VALID_MAPPING equ 1 |
25 | ARP_VALID_MAPPING equ 1 |
22 | ARP_AWAITING_RESPONSE equ 2 |
26 | ARP_AWAITING_RESPONSE equ 2 |
23 | ARP_RESPONSE_TIMEOUT equ 3 |
27 | ARP_RESPONSE_TIMEOUT equ 3 |
24 | 28 | ||
25 | struc ARP_ENTRY ;=14 bytes |
29 | struc ARP_ENTRY ;=14 bytes |
26 | { .IP dd ? ;+00 |
30 | { .IP dd ? ;+00 |
27 | .MAC dp ? ;+04 |
31 | .MAC dp ? ;+04 |
28 | .Status dw ? ;+10 |
32 | .Status dw ? ;+10 |
29 | .TTL dw ? ;+12 : ( in seconds ) |
33 | .TTL dw ? ;+12 : ( in seconds ) |
30 | } |
34 | } |
31 | 35 | ||
32 | virtual at 0 |
36 | virtual at 0 |
33 | ARP_ENTRY ARP_ENTRY |
37 | ARP_ENTRY ARP_ENTRY |
34 | end virtual |
38 | end virtual |
35 | 39 | ||
36 | ; The TTL field is decremented every second, and is deleted when it |
40 | ; The TTL field is decremented every second, and is deleted when it |
37 | ; reaches 0. It is refreshed every time a packet is received |
41 | ; reaches 0. It is refreshed every time a packet is received |
38 | ; If the TTL field is 0xFFFF it is a static entry and is never deleted |
42 | ; If the TTL field is 0xFFFF it is a static entry and is never deleted |
39 | ; The status field can be the following values: |
43 | ; The status field can be the following values: |
40 | ; 0x0000 entry not used |
44 | ; 0x0000 entry not used |
41 | ; 0x0001 entry holds a valid mapping |
45 | ; 0x0001 entry holds a valid mapping |
42 | ; 0x0002 entry contains an IP address, awaiting ARP response |
46 | ; 0x0002 entry contains an IP address, awaiting ARP response |
43 | ; 0x0003 No response received to ARP request. |
47 | ; 0x0003 No response received to ARP request. |
44 | ; The last status value is provided to allow the network layer to delete |
48 | ; The last status value is provided to allow the network layer to delete |
45 | ; a packet that is queued awaiting an ARP response |
49 | ; a packet that is queued awaiting an ARP response |
46 | 50 | ||
47 | 51 | ||
48 | ; The follow is the ARP Table. |
52 | ; The follow is the ARP Table. |
49 | ; This table must be manually updated and the kernel recompilied if |
53 | ; This table must be manually updated and the kernel recompilied if |
50 | ; changes are made to it. |
54 | ; changes are made to it. |
51 | ; Empty entries are filled with zeros |
55 | ; Empty entries are filled with zeros |
52 | 56 | ||
53 | ARP_ENTRY_SIZE equ 14 ; Number of bytes per entry |
57 | ARP_ENTRY_SIZE equ 14 ; Number of bytes per entry |
54 | ARP_TABLE_SIZE equ 20 ; Size of table |
58 | ARP_TABLE_SIZE equ 20 ; Size of table |
55 | ARP_TABLE_ENTRIES equ 0 ; Number of static entries in the table |
59 | ARP_TABLE_ENTRIES equ 0 ; Number of static entries in the table |
56 | 60 | ||
57 | ;TO ADD A STATIC ENTRY, DONT FORGET, PUT "ARPTable" from "uglobal" to "iglobal"!!! |
61 | ;TO ADD A STATIC ENTRY, DONT FORGET, PUT "ARPTable" from "uglobal" to "iglobal"!!! |
58 | ;AND ALSO - IP and MAC have net byte-order, BUT STATUS AND TTL HAVE A MIRROR BYTE-ORDER!!! |
62 | ;AND ALSO - IP and MAC have net byte-order, BUT STATUS AND TTL HAVE A MIRROR BYTE-ORDER!!! |
59 | uglobal |
63 | uglobal |
60 | ARPTable: |
64 | ARPTable: |
61 | ;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 |
62 | 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 |
63 | endg |
67 | endg |
64 | 68 | ||
65 | iglobal |
69 | iglobal |
66 | NumARP: dd ARP_TABLE_ENTRIES |
70 | NumARP: dd ARP_TABLE_ENTRIES |
67 | ARPTable_ptr dd ARPTable ;pointer to ARPTable |
71 | ARPTable_ptr dd ARPTable ;pointer to ARPTable |
68 | endg |
72 | endg |
69 | 73 | ||
70 | ARP_REQ_OPCODE equ 0x0100 ;request |
74 | ARP_REQ_OPCODE equ 0x0100 ;request |
71 | ARP_REP_OPCODE equ 0x0200 ;reply |
75 | ARP_REP_OPCODE equ 0x0200 ;reply |
72 | 76 | ||
73 | struc ARP_PACKET |
77 | struc ARP_PACKET |
74 | { .HardwareType dw ? ;+00 |
78 | { .HardwareType dw ? ;+00 |
75 | .ProtocolType dw ? ;+02 |
79 | .ProtocolType dw ? ;+02 |
76 | .HardwareSize db ? ;+04 |
80 | .HardwareSize db ? ;+04 |
77 | .ProtocolSize db ? ;+05 |
81 | .ProtocolSize db ? ;+05 |
78 | .Opcode dw ? ;+06 |
82 | .Opcode dw ? ;+06 |
79 | .SenderMAC dp ? ;+08 |
83 | .SenderMAC dp ? ;+08 |
80 | .SenderIP dd ? ;+14 |
84 | .SenderIP dd ? ;+14 |
81 | .TargetMAC dp ? ;+18 |
85 | .TargetMAC dp ? ;+18 |
82 | .TargetIP dd ? ;+24 |
86 | .TargetIP dd ? ;+24 |
83 | } |
87 | } |
84 | 88 | ||
85 | virtual at 0 |
89 | virtual at 0 |
86 | ARP_PACKET ARP_PACKET |
90 | ARP_PACKET ARP_PACKET |
87 | end virtual |
91 | end virtual |
88 | 92 | ||
89 | 93 | ||
90 | 94 | ||
91 | ;*************************************************************************** |
95 | ;*************************************************************************** |
92 | ; Function |
96 | ; Function |
93 | ; arp_table_manager [by Johnny_B] |
97 | ; arp_table_manager [by Johnny_B] |
94 | ; |
98 | ; |
95 | ; Description |
99 | ; Description |
96 | ; Does a most required operations with ARP-table |
100 | ; Does a most required operations with ARP-table |
97 | ; IN: |
101 | ; IN: |
98 | ; Operation: see Opcode's constants below |
102 | ; Operation: see Opcode's constants below |
99 | ; Index: Index of entry in the ARP-table |
103 | ; Index: Index of entry in the ARP-table |
100 | ; Extra: Extra parameter for some Opcodes |
104 | ; Extra: Extra parameter for some Opcodes |
101 | ; OUT: |
105 | ; OUT: |
102 | ; EAX = Returned value depends on opcodes, more detailed see below |
106 | ; EAX = Returned value depends on opcodes, more detailed see below |
103 | ; |
107 | ; |
104 | ;*************************************************************************** |
108 | ;*************************************************************************** |
105 | ;Opcode's constants |
109 | ;Opcode's constants |
106 | ARP_TABLE_ADD equ 1 |
110 | ARP_TABLE_ADD equ 1 |
107 | ARP_TABLE_DEL equ 2 |
111 | ARP_TABLE_DEL equ 2 |
108 | ARP_TABLE_GET equ 3 |
112 | ARP_TABLE_GET equ 3 |
109 | ARP_TABLE_GET_ENTRIES_NUMBER equ 4 |
113 | ARP_TABLE_GET_ENTRIES_NUMBER equ 4 |
110 | ARP_TABLE_IP_TO_MAC equ 5 |
114 | ARP_TABLE_IP_TO_MAC equ 5 |
111 | ARP_TABLE_TIMER equ 6 |
115 | ARP_TABLE_TIMER equ 6 |
112 | 116 | ||
113 | ;Index's constants |
117 | ;Index's constants |
114 | EXTRA_IS_ARP_PACKET_PTR equ 0 ;if Extra contain pointer to ARP_PACKET |
118 | EXTRA_IS_ARP_PACKET_PTR equ 0 ;if Extra contain pointer to ARP_PACKET |
115 | EXTRA_IS_ARP_ENTRY_PTR equ -1 ;if Extra contain pointer to ARP_ENTRY |
119 | EXTRA_IS_ARP_ENTRY_PTR equ -1 ;if Extra contain pointer to ARP_ENTRY |
116 | 120 | ||
117 | align 4 |
121 | align 4 |
118 | proc arp_table_manager stdcall uses ebx esi edi ecx edx,\ |
122 | proc arp_table_manager stdcall uses ebx esi edi ecx edx,\ |
119 | Opcode:DWORD,Index:DWORD,Extra:DWORD |
123 | Opcode:DWORD,Index:DWORD,Extra:DWORD |
120 | 124 | ||
121 | mov ebx, dword[ARPTable_ptr] ;ARPTable base |
125 | mov ebx, dword[ARPTable_ptr] ;ARPTable base |
122 | mov ecx, dword[NumARP] ;ARP-entries counter |
126 | mov ecx, dword[NumARP] ;ARP-entries counter |
123 | 127 | ||
124 | mov eax, dword[Opcode] |
128 | mov eax, dword[Opcode] |
125 | cmp eax, ARP_TABLE_TIMER |
129 | cmp eax, ARP_TABLE_TIMER |
126 | je .timer |
130 | je .timer |
127 | cmp eax, ARP_TABLE_ADD |
131 | cmp eax, ARP_TABLE_ADD |
128 | je .add |
132 | je .add |
129 | cmp eax, ARP_TABLE_DEL |
133 | cmp eax, ARP_TABLE_DEL |
130 | je .del |
134 | je .del |
131 | cmp eax, ARP_TABLE_GET |
135 | cmp eax, ARP_TABLE_GET |
132 | je .get |
136 | je .get |
133 | cmp eax, ARP_TABLE_IP_TO_MAC |
137 | cmp eax, ARP_TABLE_IP_TO_MAC |
134 | je .ip_to_mac |
138 | je .ip_to_mac |
135 | cmp eax, ARP_TABLE_GET_ENTRIES_NUMBER |
139 | cmp eax, ARP_TABLE_GET_ENTRIES_NUMBER |
136 | je .get_entries_number |
140 | je .get_entries_number |
137 | jmp .exit ;if unknown opcode |
141 | jmp .exit ;if unknown opcode |
138 | 142 | ||
139 | 143 | ||
140 | ;;BEGIN TIMER |
144 | ;;BEGIN TIMER |
141 | ;;Description: it must be callback every second. It is responsible for removing expired routes. |
145 | ;;Description: it must be callback every second. It is responsible for removing expired routes. |
142 | ;;IN: Operation: ARP_TABLE_TIMER |
146 | ;;IN: Operation: ARP_TABLE_TIMER |
143 | ;; Index: must be zero |
147 | ;; Index: must be zero |
144 | ;; Extra: must be zero |
148 | ;; Extra: must be zero |
145 | ;;OUT: |
149 | ;;OUT: |
146 | ;; EAX=not defined |
150 | ;; EAX=not defined |
147 | ;; |
151 | ;; |
148 | .timer: |
152 | .timer: |
149 | test ecx, ecx |
153 | test ecx, ecx |
150 | jz .exit ;if NumARP=0 nothing to do |
154 | jz .exit ;if NumARP=0 nothing to do |
151 | sub ecx, ARP_TABLE_ENTRIES ;ecx=dynamic entries number |
155 | sub ecx, ARP_TABLE_ENTRIES ;ecx=dynamic entries number |
152 | jz .exit ;if NumARP=number of static entries then exit |
156 | jz .exit ;if NumARP=number of static entries then exit |
153 | 157 | ||
154 | add ebx, ARP_TABLE_ENTRIES*ARP_ENTRY_SIZE ;ebx=dynamic entries base |
158 | add ebx, ARP_TABLE_ENTRIES*ARP_ENTRY_SIZE ;ebx=dynamic entries base |
155 | 159 | ||
156 | .timer_loop: |
160 | .timer_loop: |
157 | movsx esi, word [ebx + ARP_ENTRY.TTL] |
161 | movsx esi, word [ebx + ARP_ENTRY.TTL] |
158 | cmp esi, 0xFFFFFFFF |
162 | cmp esi, 0xFFFFFFFF |
159 | je .timer_loop_end ;if TTL==0xFFFF then it's static entry |
163 | je .timer_loop_end ;if TTL==0xFFFF then it's static entry |
160 | 164 | ||
161 | test esi, esi |
165 | test esi, esi |
162 | jnz .timer_loop_end_with_dec ;if TTL!=0 |
166 | jnz .timer_loop_end_with_dec ;if TTL!=0 |
163 | 167 | ||
164 | ; Ok, TTL is 0 |
168 | ; Ok, TTL is 0 |
165 | ;if Status==AWAITING_RESPONSE and TTL==0 |
169 | ;if Status==AWAITING_RESPONSE and TTL==0 |
166 | ;then we have to change it to ARP_RESPONSE_TIMEOUT |
170 | ;then we have to change it to ARP_RESPONSE_TIMEOUT |
167 | cmp word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
171 | cmp word [ebx + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
168 | jne @f |
172 | jne @f |
169 | 173 | ||
170 | mov word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT |
174 | mov word [ebx + ARP_ENTRY.Status], ARP_RESPONSE_TIMEOUT |
171 | mov word [ebx + ARP_ENTRY.TTL], word 0x000A ;10 sec |
175 | mov word [ebx + ARP_ENTRY.TTL], word 0x000A ;10 sec |
172 | jmp .timer_loop_end |
176 | jmp .timer_loop_end |
173 | 177 | ||
174 | @@: |
178 | @@: |
175 | ;if TTL==0 and Status==VALID_MAPPING, we have to delete it |
179 | ;if TTL==0 and Status==VALID_MAPPING, we have to delete it |
176 | ;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too |
180 | ;if TTL==0 and Status==RESPONSE_TIMEOUT, delete too |
177 | mov esi, dword[NumARP] |
181 | mov esi, dword[NumARP] |
178 | sub esi, ecx ;esi=index of entry, will be deleted |
182 | sub esi, ecx ;esi=index of entry, will be deleted |
179 | stdcall arp_table_manager,ARP_TABLE_DEL,esi,0 ;opcode,index,extra |
183 | stdcall arp_table_manager,ARP_TABLE_DEL,esi,0 ;opcode,index,extra |
180 | jmp .timer_loop_end |
184 | jmp .timer_loop_end |
181 | 185 | ||
182 | 186 | ||
183 | .timer_loop_end_with_dec: |
187 | .timer_loop_end_with_dec: |
184 | dec word [ebx + ARP_ENTRY.TTL] ;decrease TTL |
188 | dec word [ebx + ARP_ENTRY.TTL] ;decrease TTL |
185 | .timer_loop_end: |
189 | .timer_loop_end: |
186 | add ebx, ARP_ENTRY_SIZE |
190 | add ebx, ARP_ENTRY_SIZE |
187 | loop .timer_loop |
191 | loop .timer_loop |
188 | 192 | ||
189 | jmp .exit |
193 | jmp .exit |
190 | ;;END TIMER |
194 | ;;END TIMER |
191 | 195 | ||
192 | ;;BEGIN ADD |
196 | ;;BEGIN ADD |
193 | ;;Description: it adds an entry in the table. If ARP-table already |
197 | ;;Description: it adds an entry in the table. If ARP-table already |
194 | ;; contains same IP, it will be updated. |
198 | ;; contains same IP, it will be updated. |
195 | ;;IN: Operation: ARP_TABLE_ADD |
199 | ;;IN: Operation: ARP_TABLE_ADD |
196 | ;; Index: specifies what contains Extra-parameter |
200 | ;; Index: specifies what contains Extra-parameter |
197 | ;; Extra: if Index==EXTRA_IS_ARP_PACKET_PTR, |
201 | ;; Extra: if Index==EXTRA_IS_ARP_PACKET_PTR, |
198 | ;; then Extra contains pointer to ARP_PACKET, |
202 | ;; then Extra contains pointer to ARP_PACKET, |
199 | ;; otherwise Extra contains pointer to ARP_ENTRY |
203 | ;; otherwise Extra contains pointer to ARP_ENTRY |
200 | ;;OUT: |
204 | ;;OUT: |
201 | ;; EAX=index of entry, that has been added |
205 | ;; EAX=index of entry, that has been added |
202 | ;; |
206 | ;; |
203 | .add: |
207 | .add: |
204 | 208 | ||
205 | sub esp, ARP_ENTRY_SIZE ;Allocate ARP_ENTRY_SIZE byte in stack |
209 | sub esp, ARP_ENTRY_SIZE ;Allocate ARP_ENTRY_SIZE byte in stack |
206 | 210 | ||
207 | mov esi, [Extra] ;pointer |
211 | mov esi, [Extra] ;pointer |
208 | mov edi, [Index] ;opcode |
212 | mov edi, [Index] ;opcode |
209 | 213 | ||
210 | cmp edi, EXTRA_IS_ARP_PACKET_PTR |
214 | cmp edi, EXTRA_IS_ARP_PACKET_PTR |
211 | je .arp_packet_to_entry ;if Extra contain ptr to ARP_PACKET and we have to form arp-entry |
215 | je .arp_packet_to_entry ;if Extra contain ptr to ARP_PACKET and we have to form arp-entry |
212 | ;else it contain ptr to arp-entry |
216 | ;else it contain ptr to arp-entry |
213 | 217 | ||
214 | cld |
218 | cld |
215 | ; esi already has been loaded |
219 | ; esi already has been loaded |
216 | mov edi, esp ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
220 | mov edi, esp ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
217 | mov ecx,ARP_ENTRY_SIZE/2 ;ARP_ENTRY_SIZE must be even number!!! |
221 | mov ecx,ARP_ENTRY_SIZE/2 ;ARP_ENTRY_SIZE must be even number!!! |
218 | rep movsw ;copy |
222 | rep movsw ;copy |
219 | jmp .search |
223 | jmp .search |
220 | 224 | ||
221 | .arp_packet_to_entry: |
225 | .arp_packet_to_entry: |
222 | mov edx, dword[esi + ARP_PACKET.SenderIP] ;esi=base of ARP_PACKET |
226 | mov edx, dword[esi + ARP_PACKET.SenderIP] ;esi=base of ARP_PACKET |
223 | mov [esp + ARP_ENTRY.IP], edx |
227 | mov [esp + ARP_ENTRY.IP], edx |
224 | 228 | ||
225 | cld |
229 | cld |
226 | lea esi, [esi + ARP_PACKET.SenderMAC] |
230 | lea esi, [esi + ARP_PACKET.SenderMAC] |
227 | lea edi, [esp + ARP_ENTRY.MAC] |
231 | lea edi, [esp + ARP_ENTRY.MAC] |
228 | movsd |
232 | movsd |
229 | movsw |
233 | movsw |
230 | mov word[esp + ARP_ENTRY.Status], ARP_VALID_MAPPING ; specify the type - a valid entry |
234 | mov word[esp + ARP_ENTRY.Status], ARP_VALID_MAPPING ; specify the type - a valid entry |
231 | mov word[esp + ARP_ENTRY.TTL], 0x0E10 ; = 1 hour |
235 | mov word[esp + ARP_ENTRY.TTL], 0x0E10 ; = 1 hour |
232 | 236 | ||
233 | .search: |
237 | .search: |
234 | mov edx, dword[esp + ARP_ENTRY.IP] ;edx=IP-address, which we'll search |
238 | mov edx, dword[esp + ARP_ENTRY.IP] ;edx=IP-address, which we'll search |
235 | mov ecx, dword[NumARP] ;ecx=ARP-entries counter |
239 | mov ecx, dword[NumARP] ;ecx=ARP-entries counter |
236 | jecxz .add_to_end ;if ARP-entries number == 0 |
240 | jecxz .add_to_end ;if ARP-entries number == 0 |
237 | imul eax, ecx, ARP_ENTRY_SIZE ;eax=current table size(in bytes) |
241 | imul eax, ecx, ARP_ENTRY_SIZE ;eax=current table size(in bytes) |
238 | @@: |
242 | @@: |
239 | sub eax, ARP_ENTRY_SIZE |
243 | sub eax, ARP_ENTRY_SIZE |
240 | cmp dword[ebx + eax + ARP_ENTRY.IP], edx |
244 | cmp dword[ebx + eax + ARP_ENTRY.IP], edx |
241 | loopnz @b |
245 | loopnz @b |
242 | jz .replace ; found, replace existing entry, ptr to it is in eax |
246 | jz .replace ; found, replace existing entry, ptr to it is in eax |
243 | 247 | ||
244 | .add_to_end: |
248 | .add_to_end: |
245 | ;else add to end |
249 | ;else add to end |
246 | or eax,-1 ;set eax=0xFFFFFFFF if adding is impossible |
250 | or eax,-1 ;set eax=0xFFFFFFFF if adding is impossible |
247 | mov ecx, dword[NumARP] |
251 | mov ecx, dword[NumARP] |
248 | cmp ecx, ARP_TABLE_SIZE |
252 | cmp ecx, ARP_TABLE_SIZE |
249 | je .add_exit ;if arp-entries number is equal to arp-table maxsize |
253 | je .add_exit ;if arp-entries number is equal to arp-table maxsize |
250 | 254 | ||
251 | imul eax, dword[NumARP], ARP_ENTRY_SIZE ;eax=ptr to end of ARPTable |
255 | imul eax, dword[NumARP], ARP_ENTRY_SIZE ;eax=ptr to end of ARPTable |
252 | inc dword [NumARP] ;increase ARP-entries counter |
256 | inc dword [NumARP] ;increase ARP-entries counter |
253 | 257 | ||
254 | .replace: |
258 | .replace: |
255 | cld |
259 | cld |
256 | mov esi, esp ;esp=base of ARP-entry, that will be added |
260 | mov esi, esp ;esp=base of ARP-entry, that will be added |
257 | lea edi, [ebx + eax] ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
261 | lea edi, [ebx + eax] ;ebx + eax=ARPTable_base + ARP-entry_base(where we will add) |
258 | mov ecx,ARP_ENTRY_SIZE/2 ;ARP_ENTRY_SIZE must be even number!!! |
262 | mov ecx,ARP_ENTRY_SIZE/2 ;ARP_ENTRY_SIZE must be even number!!! |
259 | rep movsw |
263 | rep movsw |
260 | 264 | ||
261 | mov ecx, ARP_ENTRY_SIZE |
265 | mov ecx, ARP_ENTRY_SIZE |
262 | xor edx, edx ;"div" takes operand from EDX:EAX |
266 | xor edx, edx ;"div" takes operand from EDX:EAX |
263 | div ecx ;eax=index of entry, which has been added |
267 | div ecx ;eax=index of entry, which has been added |
264 | 268 | ||
265 | .add_exit: |
269 | .add_exit: |
266 | add esp, ARP_ENTRY_SIZE ;free stack |
270 | add esp, ARP_ENTRY_SIZE ;free stack |
267 | jmp .exit |
271 | jmp .exit |
268 | ;;END ADD |
272 | ;;END ADD |
269 | 273 | ||
270 | ;;BEGIN DEL |
274 | ;;BEGIN DEL |
271 | ;;Description: it deletes an entry in the table. |
275 | ;;Description: it deletes an entry in the table. |
272 | ;;IN: Operation: ARP_TABLE_DEL |
276 | ;;IN: Operation: ARP_TABLE_DEL |
273 | ;; Index: index of entry, that should be deleted |
277 | ;; Index: index of entry, that should be deleted |
274 | ;; Extra: must be zero |
278 | ;; Extra: must be zero |
275 | ;;OUT: |
279 | ;;OUT: |
276 | ;; EAX=not defined |
280 | ;; EAX=not defined |
277 | ;; |
281 | ;; |
278 | .del: |
282 | .del: |
279 | mov esi, [Index] |
283 | mov esi, [Index] |
280 | imul esi, ARP_ENTRY_SIZE |
284 | imul esi, ARP_ENTRY_SIZE |
281 | 285 | ||
282 | mov ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY_SIZE |
286 | mov ecx, (ARP_TABLE_SIZE - 1) * ARP_ENTRY_SIZE |
283 | sub ecx, esi |
287 | sub ecx, esi |
284 | 288 | ||
285 | lea edi, [ebx + esi] ;edi=ptr to entry that should be deleted |
289 | lea edi, [ebx + esi] ;edi=ptr to entry that should be deleted |
286 | lea esi, [edi + ARP_ENTRY_SIZE] ;esi=ptr to next entry |
290 | lea esi, [edi + ARP_ENTRY_SIZE] ;esi=ptr to next entry |
287 | 291 | ||
288 | shr ecx,1 ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER! |
292 | shr ecx,1 ;ecx/2 => ARP_ENTRY_SIZE MUST BE EVEN NUMBER! |
289 | cld |
293 | cld |
290 | rep movsw |
294 | rep movsw |
291 | 295 | ||
292 | dec dword[NumARP] ;decrease arp-entries counter |
296 | dec dword[NumARP] ;decrease arp-entries counter |
293 | jmp .exit |
297 | jmp .exit |
294 | ;;END DEL |
298 | ;;END DEL |
295 | 299 | ||
296 | ;;BEGIN GET |
300 | ;;BEGIN GET |
297 | ;;Description: it reads an entry of table into buffer. |
301 | ;;Description: it reads an entry of table into buffer. |
298 | ;;IN: Operation: ARP_TABLE_GET |
302 | ;;IN: Operation: ARP_TABLE_GET |
299 | ;; Index: index of entry, that should be read |
303 | ;; Index: index of entry, that should be read |
300 | ;; Extra: pointer to buffer for reading(size must be equal to ARP_ENTRY_SIZE) |
304 | ;; Extra: pointer to buffer for reading(size must be equal to ARP_ENTRY_SIZE) |
301 | ;;OUT: |
305 | ;;OUT: |
302 | ;; EAX=not defined |
306 | ;; EAX=not defined |
303 | ;; |
307 | ;; |
304 | .get: |
308 | .get: |
305 | mov esi, [Index] |
309 | mov esi, [Index] |
306 | imul esi, ARP_ENTRY_SIZE ;esi=ptr to required ARP_ENTRY |
310 | imul esi, ARP_ENTRY_SIZE ;esi=ptr to required ARP_ENTRY |
307 | mov edi, [Extra] ;edi=buffer for reading |
311 | mov edi, [Extra] ;edi=buffer for reading |
308 | mov ecx, ARP_ENTRY_SIZE/2 ; must be even number!!! |
312 | mov ecx, ARP_ENTRY_SIZE/2 ; must be even number!!! |
309 | cld |
313 | cld |
310 | rep movsw |
314 | rep movsw |
311 | jmp .exit |
315 | jmp .exit |
312 | ;;END GET |
316 | ;;END GET |
313 | 317 | ||
314 | ;;BEGIN IP_TO_MAC |
318 | ;;BEGIN IP_TO_MAC |
315 | ;;Description: it gets an IP from Index, scans each entry in the table and writes |
319 | ;;Description: it gets an IP from Index, scans each entry in the table and writes |
316 | ;; MAC, that relates to specified IP, into buffer specified in Extra. |
320 | ;; MAC, that relates to specified IP, into buffer specified in Extra. |
317 | ;; And if it cannot find an IP-address in the table, it does an ARP-request of that. |
321 | ;; And if it cannot find an IP-address in the table, it does an ARP-request of that. |
318 | ;;IN: Operation: ARP_TABLE_IP_TO_MAC |
322 | ;;IN: Operation: ARP_TABLE_IP_TO_MAC |
319 | ;; Index: IP that should be transformed into MAC |
323 | ;; Index: IP that should be transformed into MAC |
320 | ;; Extra: pointer to buffer where will be written the MAC-address. |
324 | ;; Extra: pointer to buffer where will be written the MAC-address. |
321 | ;;OUT: |
325 | ;;OUT: |
322 | ;; EAX=ARP table entry status code. |
326 | ;; EAX=ARP table entry status code. |
323 | ;; If EAX==ARP_NO_ENTRY, IP isn't found in the table and we have sent the request. |
327 | ;; If EAX==ARP_NO_ENTRY, IP isn't found in the table and we have sent the request. |
324 | ;; If EAX==ARP_AWAITING_RESPONSE, we wait the response from remote system. |
328 | ;; If EAX==ARP_AWAITING_RESPONSE, we wait the response from remote system. |
325 | ;; If EAX==ARP_RESPONSE_TIMEOUT, remote system not responds too long. |
329 | ;; If EAX==ARP_RESPONSE_TIMEOUT, remote system not responds too long. |
326 | ;; If EAX==ARP_VALID_MAPPING, all is ok, we've got a true MAC. |
330 | ;; If EAX==ARP_VALID_MAPPING, all is ok, we've got a true MAC. |
327 | ;; |
331 | ;; |
328 | ;; If MAC will equal to a zero, in the buffer. It means, that IP-address was not yet |
332 | ;; If MAC will equal to a zero, in the buffer. It means, that IP-address was not yet |
329 | ;; resolved, or that doesn't exist. I recommend you, to do at most 3-5 calls of this |
333 | ;; resolved, or that doesn't exist. I recommend you, to do at most 3-5 calls of this |
330 | ;; function with 1sec delay. sure, only if it not return a valid MAC after a first call. |
334 | ;; function with 1sec delay. sure, only if it not return a valid MAC after a first call. |
331 | ;; |
335 | ;; |
332 | .ip_to_mac: |
336 | .ip_to_mac: |
333 | 337 | ||
334 | xor eax, eax |
338 | xor eax, eax |
335 | mov edi, dword[Extra] |
339 | mov edi, dword[Extra] |
336 | cld |
340 | cld |
337 | stosd |
341 | stosd |
338 | stosw |
342 | stosw |
339 | 343 | ||
340 | cmp dword[NumARP], 0 |
344 | cmp dword[NumARP], 0 |
341 | je .ip_to_mac_send_request ;if ARP-table not contain an entries, we have to request IP. |
345 | je .ip_to_mac_send_request ;if ARP-table not contain an entries, we have to request IP. |
342 | ;EAX will be containing a zero, it's equal to ARP_NO_ENTRY |
346 | ;EAX will be containing a zero, it's equal to ARP_NO_ENTRY |
343 | 347 | ||
344 | ; first, check destination IP to see if it is on 'this' network. |
348 | ; first, check destination IP to see if it is on 'this' network. |
345 | ; The test is: |
349 | ; The test is: |
346 | ; if ( destIP & subnet_mask == stack_ip & subnet_mask ) |
350 | ; if ( destIP & subnet_mask == stack_ip & subnet_mask ) |
347 | ; destination is local |
351 | ; destination is local |
348 | ; else |
352 | ; else |
349 | ; destination is remote, so pass to gateway |
353 | ; destination is remote, so pass to gateway |
350 | 354 | ||
351 | mov eax, [Index] ;eax=required IP |
355 | mov eax, [Index] ;eax=required IP |
352 | mov esi, eax |
356 | mov esi, eax |
353 | and esi, [subnet_mask] |
357 | and esi, [subnet_mask] |
354 | mov ecx, [stack_ip] |
358 | mov ecx, [stack_ip] |
355 | and ecx, [subnet_mask] |
359 | and ecx, [subnet_mask] |
356 | cmp esi, ecx |
360 | cmp esi, ecx |
357 | je @f ;if we and target IP are located in the same network |
361 | je @f ;if we and target IP are located in the same network |
358 | mov eax, [gateway_ip] |
362 | mov eax, [gateway_ip] |
359 | @@: |
363 | @@: |
360 | 364 | ||
361 | mov ecx, dword[NumARP] |
365 | mov ecx, dword[NumARP] |
362 | imul esi, ecx, ARP_ENTRY_SIZE ;esi=current ARP-table size |
366 | imul esi, ecx, ARP_ENTRY_SIZE ;esi=current ARP-table size |
363 | 367 | ||
364 | @@: |
368 | @@: |
365 | sub esi, ARP_ENTRY_SIZE |
369 | sub esi, ARP_ENTRY_SIZE |
366 | cmp [ebx + esi], eax ; ebx=ARPTable base |
370 | cmp [ebx + esi], eax ; ebx=ARPTable base |
367 | loopnz @b ; Return back if non match |
371 | loopnz @b ; Return back if non match |
368 | jnz .ip_to_mac_send_request ; and request IP->MAC if none found in the table |
372 | jnz .ip_to_mac_send_request ; and request IP->MAC if none found in the table |
369 | 373 | ||
370 | ; Return the entry status in eax |
374 | ; Return the entry status in eax |
371 | movzx eax, word[ebx + esi + ARP_ENTRY.Status] |
375 | movzx eax, word[ebx + esi + ARP_ENTRY.Status] |
372 | 376 | ||
373 | ; esi holds index |
377 | ; esi holds index |
374 | cld |
378 | cld |
375 | lea esi, [ebx + esi + ARP_ENTRY.MAC] |
379 | lea esi, [ebx + esi + ARP_ENTRY.MAC] |
376 | mov edi, [Extra] ;edi=ptr to buffer for write MAC |
380 | mov edi, [Extra] ;edi=ptr to buffer for write MAC |
377 | movsd |
381 | movsd |
378 | movsw |
382 | movsw |
379 | jmp .exit |
383 | jmp .exit |
380 | 384 | ||
381 | .ip_to_mac_send_request: |
385 | .ip_to_mac_send_request: |
382 | stdcall arp_request,[Index],stack_ip,node_addr ;TargetIP,SenderIP_ptr,SenderMAC_ptr |
386 | stdcall arp_request,[Index],stack_ip,node_addr ;TargetIP,SenderIP_ptr,SenderMAC_ptr |
383 | mov eax, ARP_NO_ENTRY |
387 | mov eax, ARP_NO_ENTRY |
384 | jmp .exit |
388 | jmp .exit |
385 | 389 | ||
386 | ;;END IP_TO_MAC |
390 | ;;END IP_TO_MAC |
387 | 391 | ||
388 | ;;BEGIN GET_ENTRIES_NUMBER |
392 | ;;BEGIN GET_ENTRIES_NUMBER |
389 | ;;Description: returns an ARP-entries number in the ARPTable |
393 | ;;Description: returns an ARP-entries number in the ARPTable |
390 | ;;IN: Operation: ARP_TABLE_GET_ENTRIES_NUMBER |
394 | ;;IN: Operation: ARP_TABLE_GET_ENTRIES_NUMBER |
391 | ;; Index: must be zero |
395 | ;; Index: must be zero |
392 | ;; Extra: must be zero |
396 | ;; Extra: must be zero |
393 | ;;OUT: |
397 | ;;OUT: |
394 | ;; EAX=ARP-entries number in the ARPTable |
398 | ;; EAX=ARP-entries number in the ARPTable |
395 | .get_entries_number: |
399 | .get_entries_number: |
396 | mov eax, dword[NumARP] |
400 | mov eax, dword[NumARP] |
397 | jmp .exit |
401 | jmp .exit |
398 | ;;END GET_ENTRIES_NUMBER |
402 | ;;END GET_ENTRIES_NUMBER |
399 | 403 | ||
400 | .exit: |
404 | .exit: |
401 | ret |
405 | ret |
402 | endp |
406 | endp |
403 | 407 | ||
404 | 408 | ||
405 | ;*************************************************************************** |
409 | ;*************************************************************************** |
406 | ; Function |
410 | ; Function |
407 | ; arp_handler |
411 | ; arp_handler |
408 | ; |
412 | ; |
409 | ; Description |
413 | ; Description |
410 | ; Called when an ARP packet is received on the ethernet |
414 | ; Called when an ARP packet is received on the ethernet |
411 | ; Header + Data is in Ether_buffer[] |
415 | ; Header + Data is in Ether_buffer[] |
412 | ; It looks to see if the packet is a request to resolve this Hosts |
416 | ; It looks to see if the packet is a request to resolve this Hosts |
413 | ; IP address. If it is, send the ARP reply packet. |
417 | ; IP address. If it is, send the ARP reply packet. |
414 | ; This Hosts IP address is in dword [stack_ip] ( in network format ) |
418 | ; This Hosts IP address is in dword [stack_ip] ( in network format ) |
415 | ; This Hosts MAC address is in node_addr[6] |
419 | ; This Hosts MAC address is in node_addr[6] |
416 | ; All registers may be destroyed |
420 | ; All registers may be destroyed |
417 | ; |
421 | ; |
418 | ;*************************************************************************** |
422 | ;*************************************************************************** |
419 | arp_handler: |
423 | arp_handler: |
420 | ; Is this a REQUEST? |
424 | ; Is this a REQUEST? |
421 | ; Is this a request for My Host IP |
425 | ; Is this a request for My Host IP |
422 | ; Yes - So construct a response message. |
426 | ; Yes - So construct a response message. |
423 | ; Send this message to the ethernet card for transmission |
427 | ; Send this message to the ethernet card for transmission |
424 | 428 | ||
425 | stdcall arp_table_manager,ARP_TABLE_ADD,EXTRA_IS_ARP_PACKET_PTR,ETH_FRAME.Data + ARP_PACKET |
429 | stdcall arp_table_manager,ARP_TABLE_ADD,EXTRA_IS_ARP_PACKET_PTR,ETH_FRAME.Data + ARP_PACKET |
426 | 430 | ||
427 | inc dword[arp_rx_count] ;increase ARP-packets counter |
431 | inc dword[arp_rx_count] ;increase ARP-packets counter |
428 | 432 | ||
429 | cmp word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REQ_OPCODE ; Is this a request packet? |
433 | cmp word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REQ_OPCODE ; Is this a request packet? |
430 | jne .exit ; No - so exit |
434 | jne .exit ; No - so exit |
431 | 435 | ||
432 | mov eax, [stack_ip] |
436 | mov eax, [stack_ip] |
433 | cmp eax, dword[ETH_FRAME.Data + ARP_PACKET.TargetIP] ; Is it looking for my IP address? |
437 | cmp eax, dword[ETH_FRAME.Data + ARP_PACKET.TargetIP] ; Is it looking for my IP address? |
434 | jne .exit ; No - so quit now |
438 | jne .exit ; No - so quit now |
435 | 439 | ||
436 | ; OK, it is a request for my MAC address. Build the frame and send it |
440 | ; OK, it is a request for my MAC address. Build the frame and send it |
437 | ; We can reuse the packet. |
441 | ; We can reuse the packet. |
438 | 442 | ||
439 | mov word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REP_OPCODE |
443 | mov word[ETH_FRAME.Data + ARP_PACKET.Opcode], ARP_REP_OPCODE |
440 | 444 | ||
441 | cld |
445 | cld |
442 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
446 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
443 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC |
447 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC |
444 | movsd |
448 | movsd |
445 | movsw |
449 | movsw |
446 | 450 | ||
447 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
451 | mov esi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
448 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetIP |
452 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetIP |
449 | movsd |
453 | movsd |
450 | 454 | ||
451 | mov esi, node_addr |
455 | mov esi, node_addr |
452 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
456 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderMAC |
453 | movsd |
457 | movsd |
454 | movsw |
458 | movsw |
455 | 459 | ||
456 | mov esi, stack_ip |
460 | mov esi, stack_ip |
457 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
461 | mov edi, ETH_FRAME.Data + ARP_PACKET.SenderIP |
458 | movsd |
462 | movsd |
459 | 463 | ||
460 | ; Now, send it! |
464 | ; Now, send it! |
461 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC ;ptr to destination MAC address |
465 | mov edi, ETH_FRAME.Data + ARP_PACKET.TargetMAC ;ptr to destination MAC address |
462 | mov bx, ETHER_ARP ;type of protocol |
466 | mov bx, ETHER_ARP ;type of protocol |
463 | mov ecx, 28 ;data size |
467 | mov ecx, 28 ;data size |
464 | mov esi, ETH_FRAME.Data + ARP_PACKET ;ptr to data |
468 | mov esi, ETH_FRAME.Data + ARP_PACKET ;ptr to data |
465 | call dword [drvr_transmit] ;transmit packet |
469 | call dword [drvr_transmit] ;transmit packet |
466 | 470 | ||
467 | .exit: |
471 | .exit: |
468 | ret |
472 | ret |
469 | 473 | ||
470 | 474 | ||
471 | ;*************************************************************************** |
475 | ;*************************************************************************** |
472 | ; Function |
476 | ; Function |
473 | ; arp_request [by Johnny_B] |
477 | ; arp_request [by Johnny_B] |
474 | ; |
478 | ; |
475 | ; Description |
479 | ; Description |
476 | ; Sends an ARP request on the ethernet |
480 | ; Sends an ARP request on the ethernet |
477 | ; IN: |
481 | ; IN: |
478 | ; TargetIP : requested IP address |
482 | ; TargetIP : requested IP address |
479 | ; SenderIP_ptr : POINTER to sender's IP address(our system's address) |
483 | ; SenderIP_ptr : POINTER to sender's IP address(our system's address) |
480 | ; SenderMAC_ptr : POINTER to sender's MAC address(our system's address) |
484 | ; SenderMAC_ptr : POINTER to sender's MAC address(our system's address) |
481 | ; OUT: |
485 | ; OUT: |
482 | ; EAX=0 (if all is ok), otherwise EAX is not defined |
486 | ; EAX=0 (if all is ok), otherwise EAX is not defined |
483 | ; |
487 | ; |
484 | ; EBX,ESI,EDI will be saved |
488 | ; EBX,ESI,EDI will be saved |
485 | ; |
489 | ; |
486 | ;*************************************************************************** |
490 | ;*************************************************************************** |
487 | proc arp_request stdcall uses ebx esi edi,\ |
491 | proc arp_request stdcall uses ebx esi edi,\ |
488 | TargetIP:DWORD, SenderIP_ptr:DWORD, SenderMAC_ptr:DWORD |
492 | TargetIP:DWORD, SenderIP_ptr:DWORD, SenderMAC_ptr:DWORD |
489 | 493 | ||
490 | inc dword[arp_tx_count] ; increase counter |
494 | inc dword[arp_tx_count] ; increase counter |
491 | 495 | ||
492 | sub esp, 28 ; allocate memory for ARP_PACKET |
496 | sub esp, 28 ; allocate memory for ARP_PACKET |
493 | 497 | ||
494 | mov word[esp + ARP_PACKET.HardwareType],0x0100 ;Ethernet |
498 | mov word[esp + ARP_PACKET.HardwareType],0x0100 ;Ethernet |
495 | mov word[esp + ARP_PACKET.ProtocolType],0x0008 ;IP |
499 | mov word[esp + ARP_PACKET.ProtocolType],0x0008 ;IP |
496 | mov byte[esp + ARP_PACKET.HardwareSize],0x06 ;MAC-addr length |
500 | mov byte[esp + ARP_PACKET.HardwareSize],0x06 ;MAC-addr length |
497 | mov byte[esp + ARP_PACKET.ProtocolSize],0x04 ;IP-addr length |
501 | mov byte[esp + ARP_PACKET.ProtocolSize],0x04 ;IP-addr length |
498 | mov word[esp + ARP_PACKET.Opcode],0x0100 ;Request |
502 | mov word[esp + ARP_PACKET.Opcode],0x0100 ;Request |
499 | 503 | ||
500 | cld |
504 | cld |
501 | mov esi,[SenderMAC_ptr] |
505 | mov esi,[SenderMAC_ptr] |
502 | lea edi,[esp + ARP_PACKET.SenderMAC] ;Our MAC-addr |
506 | lea edi,[esp + ARP_PACKET.SenderMAC] ;Our MAC-addr |
503 | movsd |
507 | movsd |
504 | movsw |
508 | movsw |
505 | 509 | ||
506 | mov esi,[SenderIP_ptr] |
510 | mov esi,[SenderIP_ptr] |
507 | lea edi,[esp + ARP_PACKET.SenderIP] ;Our IP-addr |
511 | lea edi,[esp + ARP_PACKET.SenderIP] ;Our IP-addr |
508 | movsd |
512 | movsd |
509 | 513 | ||
510 | xor eax, eax |
514 | xor eax, eax |
511 | lea edi, [esp + ARP_PACKET.TargetMAC] ;Required MAC-addr(zeroed) |
515 | lea edi, [esp + ARP_PACKET.TargetMAC] ;Required MAC-addr(zeroed) |
512 | stosd |
516 | stosd |
513 | stosw |
517 | stosw |
514 | 518 | ||
515 | mov esi, dword[TargetIP] |
519 | mov esi, dword[TargetIP] |
516 | mov dword[esp + ARP_PACKET.TargetIP],esi ;Required IP-addr(we get it as function parameter) |
520 | mov dword[esp + ARP_PACKET.TargetIP],esi ;Required IP-addr(we get it as function parameter) |
517 | 521 | ||
518 | ; Now, send it! |
522 | ; Now, send it! |
519 | mov edi, broadcast_add ; Pointer to 48 bit destination address |
523 | mov edi, broadcast_add ; Pointer to 48 bit destination address |
520 | mov bx, ETHER_ARP ; Type of packet |
524 | mov bx, ETHER_ARP ; Type of packet |
521 | mov ecx, 28 ; size of packet |
525 | mov ecx, 28 ; size of packet |
522 | lea esi, [esp + ARP_PACKET]; pointer to packet data |
526 | lea esi, [esp + ARP_PACKET]; pointer to packet data |
523 | call dword [drvr_transmit] ; Call the drivers transmit function |
527 | call dword [drvr_transmit] ; Call the drivers transmit function |
524 | 528 | ||
525 | add esp, 28 ; free memory, allocated before for ARP_PACKET |
529 | add esp, 28 ; free memory, allocated before for ARP_PACKET |
526 | 530 | ||
527 | ; Add an entry in the ARP table, awaiting response |
531 | ; Add an entry in the ARP table, awaiting response |
528 | sub esp, ARP_ENTRY_SIZE ;allocate memory for ARP-entry |
532 | sub esp, ARP_ENTRY_SIZE ;allocate memory for ARP-entry |
529 | 533 | ||
530 | mov esi, dword[TargetIP] |
534 | mov esi, dword[TargetIP] |
531 | mov dword[esp + ARP_ENTRY.IP],esi |
535 | mov dword[esp + ARP_ENTRY.IP],esi |
532 | 536 | ||
533 | lea edi, [esp + ARP_ENTRY.MAC] |
537 | lea edi, [esp + ARP_ENTRY.MAC] |
534 | xor eax, eax |
538 | xor eax, eax |
535 | stosd |
539 | stosd |
536 | stosw |
540 | stosw |
537 | 541 | ||
538 | mov word[esp + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
542 | mov word[esp + ARP_ENTRY.Status], ARP_AWAITING_RESPONSE |
539 | mov word[esp + ARP_ENTRY.TTL], 0x000A ; 10 seconds |
543 | mov word[esp + ARP_ENTRY.TTL], 0x000A ; 10 seconds |
540 | 544 | ||
541 | stdcall arp_table_manager,ARP_TABLE_ADD,EXTRA_IS_ARP_ENTRY_PTR,esp |
545 | stdcall arp_table_manager,ARP_TABLE_ADD,EXTRA_IS_ARP_ENTRY_PTR,esp |
542 | add esp, ARP_ENTRY_SIZE ; free memory |
546 | add esp, ARP_ENTRY_SIZE ; free memory |
543 | 547 | ||
544 | .exit: |
548 | .exit: |
545 | ret |
549 | ret |
546 | endp |
550 | endp |