]>
Commit | Line | Data |
---|---|---|
772db4bb | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | ArpMain.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | \r | |
19 | **/\r | |
20 | \r | |
21 | #include "ArpImpl.h"\r | |
22 | \r | |
23 | \r | |
24 | /**\r | |
25 | This function is used to assign a station address to the ARP cache for this instance\r | |
26 | of the ARP driver. A call to this function with the ConfigData field set to NULL\r | |
27 | will reset this ARP instance.\r | |
28 | \r | |
29 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
30 | @param ConfigData Pointer to the EFI_ARP_CONFIG_DATA structure.\r | |
31 | \r | |
32 | @retval EFI_SUCCESS The new station address was successfully\r | |
33 | registered.\r | |
34 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
35 | This is NULL. SwAddressLength is zero when\r | |
36 | ConfigData is not NULL. StationAddress is NULL\r | |
37 | when ConfigData is not NULL.\r | |
38 | @retval EFI_ACCESS_DENIED The SwAddressType, SwAddressLength, or\r | |
39 | StationAddress is different from the one that is\r | |
40 | already registered.\r | |
41 | @retval EFI_OUT_OF_RESOURCES Storage for the new StationAddress could not be\r | |
42 | allocated.\r | |
43 | \r | |
44 | **/\r | |
45 | EFI_STATUS\r | |
46 | EFIAPI\r | |
47 | ArpConfigure (\r | |
48 | IN EFI_ARP_PROTOCOL *This,\r | |
49 | IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL\r | |
50 | )\r | |
51 | {\r | |
52 | EFI_STATUS Status;\r | |
53 | ARP_INSTANCE_DATA *Instance;\r | |
36ee91ca | 54 | EFI_TPL OldTpl;\r |
772db4bb | 55 | \r |
56 | if (This == NULL) {\r | |
57 | return EFI_INVALID_PARAMETER;\r | |
58 | }\r | |
59 | \r | |
60 | if ((ConfigData != NULL) &&\r | |
61 | ((ConfigData->SwAddressLength == 0) ||\r | |
62 | (ConfigData->StationAddress == NULL) ||\r | |
63 | (ConfigData->SwAddressType <= 1500))) {\r | |
64 | return EFI_INVALID_PARAMETER;\r | |
65 | }\r | |
66 | \r | |
67 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
68 | \r | |
e48e37fc | 69 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 70 | \r |
71 | //\r | |
72 | // Configure this instance, the ConfigData has already passed the basic checks.\r | |
73 | //\r | |
74 | Status = ArpConfigureInstance (Instance, ConfigData);\r | |
75 | \r | |
e48e37fc | 76 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 77 | \r |
78 | return Status;\r | |
79 | }\r | |
80 | \r | |
81 | \r | |
82 | /**\r | |
83 | This function is used to insert entries into the ARP cache.\r | |
84 | \r | |
85 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
86 | @param DenyFlag Set to TRUE if this entry is a deny entry. Set to\r | |
87 | FALSE if this entry is a normal entry.\r | |
88 | @param TargetSwAddress Pointer to a protocol address to add (or deny).\r | |
89 | May be set to NULL if DenyFlag is TRUE.\r | |
90 | @param TargetHwAddress Pointer to a hardware address to add (or deny).\r | |
91 | May be set to NULL if DenyFlag is TRUE.\r | |
92 | @param TimeoutValue Time in 100-ns units that this entry will remain\r | |
93 | in the ARP cache. A value of zero means that the\r | |
94 | entry is permanent. A nonzero value will override\r | |
95 | the one given by Configure() if the entry to be\r | |
96 | added is a dynamic entry.\r | |
97 | @param Overwrite If TRUE, the matching cache entry will be\r | |
98 | overwritten with the supplied parameters. If\r | |
99 | FALSE, EFI_ACCESS_DENIED is returned if the\r | |
100 | corresponding cache entry already exists.\r | |
101 | \r | |
102 | @retval EFI_SUCCESS The entry has been added or updated.\r | |
103 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
104 | This is NULL. DenyFlag is FALSE and\r | |
105 | TargetHwAddress is NULL. DenyFlag is FALSE and\r | |
106 | TargetSwAddress is NULL. TargetHwAddress is NULL\r | |
107 | and TargetSwAddress is NULL. Both TargetSwAddress\r | |
108 | and TargetHwAddress are not NULL when DenyFlag is\r | |
109 | TRUE.\r | |
110 | @retval EFI_OUT_OF_RESOURCES The new ARP cache entry could not be allocated.\r | |
111 | @retval EFI_ACCESS_DENIED The ARP cache entry already exists and Overwrite\r | |
112 | is not true.\r | |
113 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
114 | \r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | ArpAdd (\r | |
119 | IN EFI_ARP_PROTOCOL *This,\r | |
120 | IN BOOLEAN DenyFlag,\r | |
121 | IN VOID *TargetSwAddress OPTIONAL,\r | |
122 | IN VOID *TargetHwAddress OPTIONAL,\r | |
123 | IN UINT32 TimeoutValue,\r | |
124 | IN BOOLEAN Overwrite\r | |
125 | )\r | |
126 | {\r | |
127 | EFI_STATUS Status;\r | |
128 | ARP_INSTANCE_DATA *Instance;\r | |
129 | ARP_SERVICE_DATA *ArpService;\r | |
130 | ARP_CACHE_ENTRY *CacheEntry;\r | |
131 | EFI_SIMPLE_NETWORK_MODE *SnpMode;\r | |
132 | NET_ARP_ADDRESS MatchAddress[2];\r | |
36ee91ca | 133 | EFI_TPL OldTpl;\r |
772db4bb | 134 | \r |
135 | if (This == NULL) {\r | |
136 | return EFI_INVALID_PARAMETER;\r | |
137 | }\r | |
138 | \r | |
139 | if (((!DenyFlag) && ((TargetHwAddress == NULL) || (TargetSwAddress == NULL))) ||\r | |
140 | (DenyFlag && (TargetHwAddress != NULL) && (TargetSwAddress != NULL)) ||\r | |
141 | ((TargetHwAddress == NULL) && (TargetSwAddress == NULL))) {\r | |
142 | return EFI_INVALID_PARAMETER;\r | |
143 | }\r | |
144 | \r | |
145 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
146 | \r | |
147 | if (!Instance->Configured) {\r | |
148 | return EFI_NOT_STARTED;\r | |
149 | }\r | |
150 | \r | |
151 | Status = EFI_SUCCESS;\r | |
152 | ArpService = Instance->ArpService;\r | |
153 | SnpMode = &Instance->ArpService->SnpMode;\r | |
154 | \r | |
155 | //\r | |
156 | // Fill the hardware address part in the MatchAddress.\r | |
157 | //\r | |
158 | MatchAddress[Hardware].Type = SnpMode->IfType;\r | |
159 | MatchAddress[Hardware].Length = (UINT8) SnpMode->HwAddressSize;\r | |
160 | MatchAddress[Hardware].AddressPtr = TargetHwAddress;\r | |
161 | \r | |
162 | //\r | |
163 | // Fill the software address part in the MatchAddress.\r | |
164 | //\r | |
165 | MatchAddress[Protocol].Type = Instance->ConfigData.SwAddressType;\r | |
166 | MatchAddress[Protocol].Length = Instance->ConfigData.SwAddressLength;\r | |
167 | MatchAddress[Protocol].AddressPtr = TargetSwAddress;\r | |
168 | \r | |
e48e37fc | 169 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 170 | \r |
171 | //\r | |
172 | // See whether the entry to add exists. Check the DeinedCacheTable first.\r | |
173 | //\r | |
174 | CacheEntry = ArpFindDeniedCacheEntry (\r | |
175 | ArpService,\r | |
176 | &MatchAddress[Protocol],\r | |
177 | &MatchAddress[Hardware]\r | |
178 | );\r | |
179 | \r | |
180 | if (CacheEntry == NULL) {\r | |
181 | //\r | |
182 | // Check the ResolvedCacheTable\r | |
183 | //\r | |
184 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
185 | &ArpService->ResolvedCacheTable,\r | |
186 | NULL,\r | |
187 | ByBoth,\r | |
188 | &MatchAddress[Protocol],\r | |
189 | &MatchAddress[Hardware]\r | |
190 | );\r | |
191 | }\r | |
192 | \r | |
193 | if ((CacheEntry != NULL) && !Overwrite) {\r | |
194 | //\r | |
195 | // The entry to add exists, if not Overwirte, deny this add request.\r | |
196 | //\r | |
197 | Status = EFI_ACCESS_DENIED;\r | |
198 | goto UNLOCK_EXIT;\r | |
199 | }\r | |
200 | \r | |
201 | if ((CacheEntry == NULL) && (TargetSwAddress != NULL)) {\r | |
202 | //\r | |
203 | // Check whether there are pending requests matching the entry to be added.\r | |
204 | //\r | |
205 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
206 | &ArpService->PendingRequestTable,\r | |
207 | NULL,\r | |
208 | ByProtoAddress,\r | |
209 | &MatchAddress[Protocol],\r | |
210 | NULL\r | |
211 | );\r | |
212 | }\r | |
213 | \r | |
214 | if (CacheEntry != NULL) {\r | |
215 | //\r | |
216 | // Remove it from the Table.\r | |
217 | //\r | |
e48e37fc | 218 | RemoveEntryList (&CacheEntry->List);\r |
772db4bb | 219 | } else {\r |
220 | //\r | |
221 | // It's a new entry, allocate memory for the entry.\r | |
222 | //\r | |
223 | CacheEntry = ArpAllocCacheEntry (Instance);\r | |
224 | \r | |
225 | if (CacheEntry == NULL) {\r | |
e48e37fc | 226 | DEBUG ((EFI_D_ERROR, "ArpAdd: Failed to allocate pool for CacheEntry.\n"));\r |
772db4bb | 227 | Status = EFI_OUT_OF_RESOURCES;\r |
228 | goto UNLOCK_EXIT;\r | |
229 | }\r | |
230 | }\r | |
231 | \r | |
232 | //\r | |
233 | // Overwrite these parameters.\r | |
234 | //\r | |
235 | CacheEntry->DefaultDecayTime = TimeoutValue;\r | |
236 | CacheEntry->DecayTime = TimeoutValue;\r | |
237 | \r | |
238 | //\r | |
239 | // Fill in the addresses.\r | |
240 | //\r | |
241 | ArpFillAddressInCacheEntry (\r | |
242 | CacheEntry,\r | |
243 | &MatchAddress[Hardware],\r | |
244 | &MatchAddress[Protocol]\r | |
245 | );\r | |
246 | \r | |
247 | //\r | |
248 | // Inform the user if there is any.\r | |
249 | //\r | |
250 | ArpAddressResolved (CacheEntry, NULL, NULL);\r | |
251 | \r | |
252 | //\r | |
253 | // Add this CacheEntry to the corresponding CacheTable.\r | |
254 | //\r | |
255 | if (DenyFlag) {\r | |
e48e37fc | 256 | InsertHeadList (&ArpService->DeniedCacheTable, &CacheEntry->List);\r |
772db4bb | 257 | } else {\r |
e48e37fc | 258 | InsertHeadList (&ArpService->ResolvedCacheTable, &CacheEntry->List);\r |
772db4bb | 259 | }\r |
260 | \r | |
261 | UNLOCK_EXIT:\r | |
262 | \r | |
e48e37fc | 263 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 264 | \r |
265 | return Status;\r | |
266 | }\r | |
267 | \r | |
268 | \r | |
269 | /**\r | |
270 | This function searches the ARP cache for matching entries and allocates a buffer into\r | |
271 | which those entries are copied.\r | |
272 | \r | |
273 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
274 | @param BySwAddress Set to TRUE to look for matching software protocol\r | |
275 | addresses. Set to FALSE to look for matching\r | |
276 | hardware protocol addresses.\r | |
277 | @param AddressBuffer Pointer to address buffer. Set to NULL to match\r | |
278 | all addresses.\r | |
279 | @param EntryLength The size of an entry in the entries buffer.\r | |
280 | @param EntryCount The number of ARP cache entries that are found by\r | |
281 | the specified criteria.\r | |
282 | @param Entries Pointer to the buffer that will receive the ARP\r | |
283 | cache entries.\r | |
284 | @param Refresh Set to TRUE to refresh the timeout value of the\r | |
285 | matching ARP cache entry.\r | |
286 | \r | |
287 | @retval EFI_SUCCESS The requested ARP cache entries were copied into\r | |
288 | the buffer.\r | |
289 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
290 | This is NULL. Both EntryCount and EntryLength are\r | |
291 | NULL, when Refresh is FALSE.\r | |
292 | @retval EFI_NOT_FOUND No matching entries were found.\r | |
293 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
294 | \r | |
295 | **/\r | |
296 | EFI_STATUS\r | |
297 | EFIAPI\r | |
298 | ArpFind (\r | |
299 | IN EFI_ARP_PROTOCOL *This,\r | |
300 | IN BOOLEAN BySwAddress,\r | |
301 | IN VOID *AddressBuffer OPTIONAL,\r | |
302 | OUT UINT32 *EntryLength OPTIONAL,\r | |
303 | OUT UINT32 *EntryCount OPTIONAL,\r | |
304 | OUT EFI_ARP_FIND_DATA **Entries OPTIONAL,\r | |
305 | IN BOOLEAN Refresh\r | |
306 | )\r | |
307 | {\r | |
308 | EFI_STATUS Status;\r | |
309 | ARP_INSTANCE_DATA *Instance;\r | |
36ee91ca | 310 | EFI_TPL OldTpl;\r |
772db4bb | 311 | \r |
312 | if ((This == NULL) ||\r | |
313 | (!Refresh && (EntryCount == NULL) && (EntryLength == NULL)) ||\r | |
314 | ((Entries != NULL) && ((EntryLength == NULL) || (EntryCount == NULL)))) {\r | |
315 | return EFI_INVALID_PARAMETER;\r | |
316 | }\r | |
317 | \r | |
318 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
772db4bb | 319 | \r |
320 | if (!Instance->Configured) {\r | |
321 | return EFI_NOT_STARTED;\r | |
322 | }\r | |
323 | \r | |
e48e37fc | 324 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 325 | \r |
326 | //\r | |
327 | // All the check passed, find the cache entries now.\r | |
328 | //\r | |
329 | Status = ArpFindCacheEntry (\r | |
330 | Instance,\r | |
331 | BySwAddress,\r | |
332 | AddressBuffer,\r | |
333 | EntryLength,\r | |
334 | EntryCount,\r | |
335 | Entries,\r | |
336 | Refresh\r | |
337 | );\r | |
338 | \r | |
e48e37fc | 339 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 340 | \r |
341 | return Status;\r | |
342 | }\r | |
343 | \r | |
344 | \r | |
345 | /**\r | |
346 | This function removes specified ARP cache entries.\r | |
347 | \r | |
348 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
349 | @param BySwAddress Set to TRUE to delete matching protocol addresses.\r | |
350 | Set to FALSE to delete matching hardware\r | |
351 | addresses.\r | |
352 | @param AddressBuffer Pointer to the address buffer that is used as a\r | |
353 | key to look for the cache entry. Set to NULL to\r | |
354 | delete all entries.\r | |
355 | \r | |
356 | @retval EFI_SUCCESS The entry was removed from the ARP cache.\r | |
357 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
358 | @retval EFI_NOT_FOUND The specified deletion key was not found.\r | |
359 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
360 | \r | |
361 | **/\r | |
362 | EFI_STATUS\r | |
363 | EFIAPI\r | |
364 | ArpDelete (\r | |
365 | IN EFI_ARP_PROTOCOL *This,\r | |
366 | IN BOOLEAN BySwAddress,\r | |
367 | IN VOID *AddressBuffer OPTIONAL\r | |
368 | )\r | |
369 | {\r | |
370 | ARP_INSTANCE_DATA *Instance;\r | |
772db4bb | 371 | UINTN Count;\r |
36ee91ca | 372 | EFI_TPL OldTpl;\r |
772db4bb | 373 | \r |
374 | if (This == NULL) {\r | |
375 | return EFI_INVALID_PARAMETER;\r | |
376 | }\r | |
377 | \r | |
378 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
379 | \r | |
380 | if (!Instance->Configured) {\r | |
381 | return EFI_NOT_STARTED;\r | |
382 | }\r | |
383 | \r | |
e48e37fc | 384 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 385 | \r |
386 | //\r | |
387 | // Delete the specified cache entries.\r | |
388 | //\r | |
389 | Count = ArpDeleteCacheEntry (Instance, BySwAddress, AddressBuffer, TRUE);\r | |
390 | \r | |
e48e37fc | 391 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 392 | \r |
393 | return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;\r | |
394 | }\r | |
395 | \r | |
396 | \r | |
397 | /**\r | |
398 | This function delete all dynamic entries from the ARP cache that match the specified\r | |
399 | software protocol type.\r | |
400 | \r | |
401 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
402 | \r | |
403 | @retval EFI_SUCCESS The cache has been flushed.\r | |
404 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
405 | @retval EFI_NOT_FOUND There are no matching dynamic cache entries.\r | |
406 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
407 | \r | |
408 | **/\r | |
409 | EFI_STATUS\r | |
410 | EFIAPI\r | |
411 | ArpFlush (\r | |
412 | IN EFI_ARP_PROTOCOL *This\r | |
413 | )\r | |
414 | {\r | |
415 | ARP_INSTANCE_DATA *Instance;\r | |
772db4bb | 416 | UINTN Count;\r |
36ee91ca | 417 | EFI_TPL OldTpl;\r |
772db4bb | 418 | \r |
419 | if (This == NULL) {\r | |
420 | return EFI_INVALID_PARAMETER;\r | |
421 | }\r | |
422 | \r | |
423 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
424 | \r | |
425 | if (!Instance->Configured) {\r | |
426 | return EFI_NOT_STARTED;\r | |
427 | }\r | |
428 | \r | |
e48e37fc | 429 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 430 | \r |
431 | //\r | |
432 | // Delete the dynamic entries from the cache table.\r | |
433 | //\r | |
434 | Count = ArpDeleteCacheEntry (Instance, FALSE, NULL, FALSE);\r | |
435 | \r | |
e48e37fc | 436 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 437 | \r |
438 | return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;\r | |
439 | }\r | |
440 | \r | |
441 | \r | |
442 | /**\r | |
443 | This function tries to resolve the TargetSwAddress and optionally returns a\r | |
444 | TargetHwAddress if it already exists in the ARP cache.\r | |
445 | \r | |
446 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
447 | @param TargetSwAddress Pointer to the protocol address to resolve.\r | |
448 | @param ResolvedEvent Pointer to the event that will be signaled when\r | |
449 | the address is resolved or some error occurs.\r | |
450 | @param TargetHwAddress Pointer to the buffer for the resolved hardware\r | |
451 | address in network byte order.\r | |
452 | \r | |
453 | @retval EFI_SUCCESS The data is copied from the ARP cache into the\r | |
454 | TargetHwAddress buffer.\r | |
455 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
456 | This is NULL. TargetHwAddress is NULL.\r | |
457 | @retval EFI_ACCESS_DENIED The requested address is not present in the normal\r | |
458 | ARP cache but is present in the deny address list.\r | |
459 | Outgoing traffic to that address is forbidden.\r | |
460 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
461 | @retval EFI_NOT_READY The request has been started and is not finished.\r | |
462 | \r | |
463 | **/\r | |
464 | EFI_STATUS\r | |
465 | EFIAPI\r | |
466 | ArpRequest (\r | |
467 | IN EFI_ARP_PROTOCOL *This,\r | |
468 | IN VOID *TargetSwAddress OPTIONAL,\r | |
469 | IN EFI_EVENT ResolvedEvent OPTIONAL,\r | |
470 | OUT VOID *TargetHwAddress\r | |
471 | )\r | |
472 | {\r | |
473 | EFI_STATUS Status;\r | |
474 | ARP_INSTANCE_DATA *Instance;\r | |
475 | ARP_SERVICE_DATA *ArpService;\r | |
476 | EFI_SIMPLE_NETWORK_MODE *SnpMode;\r | |
477 | ARP_CACHE_ENTRY *CacheEntry;\r | |
478 | NET_ARP_ADDRESS HardwareAddress;\r | |
479 | NET_ARP_ADDRESS ProtocolAddress;\r | |
480 | USER_REQUEST_CONTEXT *RequestContext;\r | |
36ee91ca | 481 | EFI_TPL OldTpl;\r |
772db4bb | 482 | \r |
483 | if ((This == NULL) || (TargetHwAddress == NULL)) {\r | |
484 | return EFI_INVALID_PARAMETER;\r | |
485 | }\r | |
486 | \r | |
487 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
488 | \r | |
489 | if (!Instance->Configured) {\r | |
490 | return EFI_NOT_STARTED;\r | |
491 | }\r | |
492 | \r | |
493 | Status = EFI_SUCCESS;\r | |
494 | ArpService = Instance->ArpService;\r | |
495 | SnpMode = &ArpService->SnpMode;\r | |
496 | \r | |
497 | if ((TargetSwAddress == NULL) ||\r | |
7bce0c5a | 498 | ((Instance->ConfigData.SwAddressType == IPV4_ETHER_PROTO_TYPE) &&\r |
772db4bb | 499 | IP4_IS_LOCAL_BROADCAST (*((UINT32 *)TargetSwAddress)))) {\r |
500 | //\r | |
501 | // Return the hardware broadcast address.\r | |
502 | //\r | |
e48e37fc | 503 | CopyMem (TargetHwAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize);\r |
772db4bb | 504 | \r |
505 | goto SIGNAL_USER;\r | |
506 | }\r | |
507 | \r | |
7bce0c5a | 508 | if ((Instance->ConfigData.SwAddressType == IPV4_ETHER_PROTO_TYPE) &&\r |
772db4bb | 509 | IP4_IS_MULTICAST (NTOHL (*((UINT32 *)TargetSwAddress)))) {\r |
510 | //\r | |
511 | // If the software address is an IPv4 multicast address, invoke Mnp to\r | |
512 | // resolve the address.\r | |
513 | //\r | |
514 | Status = ArpService->Mnp->McastIpToMac (\r | |
515 | ArpService->Mnp,\r | |
516 | FALSE,\r | |
517 | TargetSwAddress,\r | |
518 | TargetHwAddress\r | |
519 | );\r | |
520 | goto SIGNAL_USER;\r | |
521 | }\r | |
522 | \r | |
523 | HardwareAddress.Type = SnpMode->IfType;\r | |
524 | HardwareAddress.Length = (UINT8)SnpMode->HwAddressSize;\r | |
525 | HardwareAddress.AddressPtr = NULL;\r | |
526 | \r | |
527 | ProtocolAddress.Type = Instance->ConfigData.SwAddressType;\r | |
528 | ProtocolAddress.Length = Instance->ConfigData.SwAddressLength;\r | |
529 | ProtocolAddress.AddressPtr = TargetSwAddress;\r | |
530 | \r | |
531 | //\r | |
532 | // Initialize the TargetHwAddrss to a zero address.\r | |
533 | //\r | |
e48e37fc | 534 | ZeroMem (TargetHwAddress, SnpMode->HwAddressSize);\r |
772db4bb | 535 | \r |
e48e37fc | 536 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 537 | \r |
538 | //\r | |
539 | // Check whether the software address is in the denied table.\r | |
540 | //\r | |
541 | CacheEntry = ArpFindDeniedCacheEntry (ArpService, &ProtocolAddress, NULL);\r | |
542 | if (CacheEntry != NULL) {\r | |
543 | Status = EFI_ACCESS_DENIED;\r | |
544 | goto UNLOCK_EXIT;\r | |
545 | }\r | |
546 | \r | |
547 | //\r | |
548 | // Check whether the software address is already resolved.\r | |
549 | //\r | |
550 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
551 | &ArpService->ResolvedCacheTable,\r | |
552 | NULL,\r | |
553 | ByProtoAddress,\r | |
554 | &ProtocolAddress,\r | |
555 | NULL\r | |
556 | );\r | |
557 | if (CacheEntry != NULL) {\r | |
558 | //\r | |
559 | // Resolved, copy the address into the user buffer.\r | |
560 | //\r | |
e48e37fc | 561 | CopyMem (\r |
772db4bb | 562 | TargetHwAddress,\r |
563 | CacheEntry->Addresses[Hardware].AddressPtr,\r | |
564 | CacheEntry->Addresses[Hardware].Length\r | |
565 | );\r | |
566 | \r | |
567 | goto UNLOCK_EXIT;\r | |
568 | }\r | |
569 | \r | |
570 | if (ResolvedEvent == NULL) {\r | |
571 | Status = EFI_NOT_READY;\r | |
572 | goto UNLOCK_EXIT;\r | |
573 | }\r | |
574 | \r | |
575 | //\r | |
576 | // Create a request context for this arp request.\r | |
577 | //\r | |
e48e37fc | 578 | RequestContext = AllocatePool (sizeof(USER_REQUEST_CONTEXT));\r |
772db4bb | 579 | if (RequestContext == NULL) {\r |
e48e37fc | 580 | DEBUG ((EFI_D_ERROR, "ArpRequest: Allocate memory for RequestContext failed.\n"));\r |
772db4bb | 581 | \r |
582 | Status = EFI_OUT_OF_RESOURCES;\r | |
583 | goto UNLOCK_EXIT;\r | |
584 | }\r | |
585 | \r | |
586 | RequestContext->Instance = Instance;\r | |
587 | RequestContext->UserRequestEvent = ResolvedEvent;\r | |
588 | RequestContext->UserHwAddrBuffer = TargetHwAddress;\r | |
e48e37fc | 589 | InitializeListHead (&RequestContext->List);\r |
772db4bb | 590 | \r |
591 | //\r | |
592 | // Check whether there is a same request.\r | |
593 | //\r | |
594 | CacheEntry = ArpFindNextCacheEntryInTable (\r | |
595 | &ArpService->PendingRequestTable,\r | |
596 | NULL,\r | |
597 | ByProtoAddress,\r | |
598 | &ProtocolAddress,\r | |
599 | NULL\r | |
600 | );\r | |
601 | if (CacheEntry != NULL) {\r | |
602 | \r | |
603 | CacheEntry->NextRetryTime = Instance->ConfigData.RetryTimeOut;\r | |
604 | CacheEntry->RetryCount = Instance->ConfigData.RetryCount;\r | |
605 | } else {\r | |
606 | //\r | |
607 | // Allocate a cache entry for this request.\r | |
608 | //\r | |
609 | CacheEntry = ArpAllocCacheEntry (Instance);\r | |
610 | if (CacheEntry == NULL) {\r | |
e48e37fc | 611 | DEBUG ((EFI_D_ERROR, "ArpRequest: Allocate memory for CacheEntry failed.\n"));\r |
612 | gBS->FreePool (RequestContext);\r | |
772db4bb | 613 | \r |
614 | Status = EFI_OUT_OF_RESOURCES;\r | |
615 | goto UNLOCK_EXIT;\r | |
616 | }\r | |
617 | \r | |
618 | //\r | |
619 | // Fill the software address.\r | |
620 | //\r | |
621 | ArpFillAddressInCacheEntry (CacheEntry, &HardwareAddress, &ProtocolAddress);\r | |
622 | \r | |
623 | //\r | |
624 | // Add this entry into the PendingRequestTable.\r | |
625 | //\r | |
e48e37fc | 626 | InsertTailList (&ArpService->PendingRequestTable, &CacheEntry->List);\r |
772db4bb | 627 | }\r |
628 | \r | |
629 | //\r | |
630 | // Link this request context into the cache entry.\r | |
631 | //\r | |
e48e37fc | 632 | InsertHeadList (&CacheEntry->UserRequestList, &RequestContext->List);\r |
772db4bb | 633 | \r |
634 | //\r | |
635 | // Send out the ARP Request frame.\r | |
636 | //\r | |
637 | ArpSendFrame (Instance, CacheEntry, ARP_OPCODE_REQUEST);\r | |
638 | Status = EFI_NOT_READY;\r | |
639 | \r | |
640 | UNLOCK_EXIT:\r | |
641 | \r | |
e48e37fc | 642 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 643 | \r |
644 | SIGNAL_USER:\r | |
645 | \r | |
646 | if ((ResolvedEvent != NULL) && (Status == EFI_SUCCESS)) {\r | |
647 | gBS->SignalEvent (ResolvedEvent);\r | |
36ee91ca | 648 | \r |
649 | //\r | |
650 | // Dispatch the DPC queued by the NotifyFunction of ResolvedEvent.\r | |
651 | //\r | |
652 | NetLibDispatchDpc ();\r | |
772db4bb | 653 | }\r |
654 | \r | |
655 | return Status;\r | |
656 | }\r | |
657 | \r | |
658 | \r | |
659 | /**\r | |
660 | This function aborts the previous ARP request (identified by This, TargetSwAddress\r | |
661 | and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().\r | |
662 | \r | |
663 | @param This Pointer to the EFI_ARP_PROTOCOL instance.\r | |
664 | @param TargetSwAddress Pointer to the protocol address in previous\r | |
665 | request session.\r | |
666 | @param ResolvedEvent Pointer to the event that is used as the\r | |
667 | notification event in previous request session.\r | |
668 | \r | |
669 | @retval EFI_SUCCESS The pending request session(s) is/are aborted and\r | |
670 | corresponding event(s) is/are signaled.\r | |
671 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
672 | This is NULL. TargetSwAddress is not NULL and\r | |
673 | ResolvedEvent is NULL. TargetSwAddress is NULL and\r | |
674 | ResolvedEvent is not NULL.\r | |
675 | @retval EFI_NOT_STARTED The ARP driver instance has not been configured.\r | |
676 | @retval EFI_NOT_FOUND The request is not issued by\r | |
677 | EFI_ARP_PROTOCOL.Request().\r | |
678 | \r | |
679 | **/\r | |
680 | EFI_STATUS\r | |
681 | EFIAPI\r | |
682 | ArpCancel (\r | |
683 | IN EFI_ARP_PROTOCOL *This,\r | |
684 | IN VOID *TargetSwAddress OPTIONAL,\r | |
685 | IN EFI_EVENT ResolvedEvent OPTIONAL\r | |
686 | )\r | |
687 | {\r | |
688 | ARP_INSTANCE_DATA *Instance;\r | |
772db4bb | 689 | UINTN Count;\r |
36ee91ca | 690 | EFI_TPL OldTpl;\r |
772db4bb | 691 | \r |
692 | if ((This == NULL) ||\r | |
693 | ((TargetSwAddress != NULL) && (ResolvedEvent == NULL)) ||\r | |
694 | ((TargetSwAddress == NULL) && (ResolvedEvent != NULL))) {\r | |
695 | return EFI_INVALID_PARAMETER;\r | |
696 | }\r | |
697 | \r | |
698 | Instance = ARP_INSTANCE_DATA_FROM_THIS (This);\r | |
699 | \r | |
700 | if (!Instance->Configured) {\r | |
701 | return EFI_NOT_STARTED;\r | |
702 | }\r | |
703 | \r | |
e48e37fc | 704 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 705 | \r |
706 | //\r | |
707 | // Cancel the specified request.\r | |
708 | //\r | |
709 | Count = ArpCancelRequest (Instance, TargetSwAddress, ResolvedEvent);\r | |
710 | \r | |
36ee91ca | 711 | //\r |
712 | // Dispatch the DPCs queued by the NotifyFunction of the events signaled\r | |
713 | // by ArpCancleRequest.\r | |
714 | //\r | |
715 | NetLibDispatchDpc ();\r | |
716 | \r | |
e48e37fc | 717 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 718 | \r |
719 | return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;\r | |
720 | }\r |