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