]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c
Remove some useless EDK_RELEASE_VERSION, EFI_SPECIFICATION_VERSION ,and review VALID_...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpMain.c
CommitLineData
8a67d61d 1/** @file\r
2\r
3Copyright (c) 2005 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 MnpMain.c\r
15\r
16Abstract:\r
17\r
18 Implementation of Managed Network Protocol public services.\r
19\r
20\r
21**/\r
22\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/BaseLib.h>\r
25\r
26#include "MnpImpl.h"\r
27\r
28\r
29/**\r
b6c4ecad 30 Returns the operational parameters for the current MNP child driver. May also\r
31 support returning the underlying SNP driver mode data. \r
32 \r
33 The GetModeData() function is used to read the current mode data (operational\r
34 parameters) from the MNP or the underlying SNP. \r
35\r
36 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
37 @param MnpConfigData Pointer to storage for MNP operational parameters. Type\r
38 EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related\r
39 Definitions" below.\r
40 @param SnpModeData Pointer to storage for SNP operational parameters. This\r
41 feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE\r
42 is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.\r
43 \r
44 @retval EFI_SUCCESS The operation completed successfully.\r
45 @retval EFI_INVALID_PARAMETER This is NULL.\r
46 @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r
47 MNP implementation.\r
48 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
49 configured. The default values are returned in\r
50 MnpConfigData if it is not NULL.\r
51 @retval Other The mode data could not be read.\r
8a67d61d 52\r
53**/\r
54EFI_STATUS\r
55EFIAPI\r
56MnpGetModeData (\r
57 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
b6c4ecad 58 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL\r
59 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r
8a67d61d 60 )\r
61{\r
62 MNP_INSTANCE_DATA *Instance;\r
63 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
64 EFI_TPL OldTpl;\r
65 EFI_STATUS Status;\r
66\r
67 if (This == NULL) {\r
68\r
69 return EFI_INVALID_PARAMETER;\r
70 }\r
71\r
72 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
73\r
e48e37fc 74 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 75\r
76 if (MnpConfigData != NULL) {\r
77 //\r
78 // Copy the instance configuration data.\r
79 //\r
687a2e5f 80 CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));\r
8a67d61d 81 }\r
82\r
83 if (SnpModeData != NULL) {\r
84 //\r
85 // Copy the underlayer Snp mode data.\r
86 //\r
87 Snp = Instance->MnpServiceData->Snp;\r
687a2e5f 88 CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r
8a67d61d 89 }\r
90\r
91 if (!Instance->Configured) {\r
92 Status = EFI_NOT_STARTED;\r
93 } else {\r
94 Status = EFI_SUCCESS;\r
95 }\r
96\r
e48e37fc 97 gBS->RestoreTPL (OldTpl);\r
8a67d61d 98\r
99 return Status;\r
100}\r
101\r
102\r
103/**\r
b6c4ecad 104 Sets or clears the operational parameters for the MNP child driver. \r
105 \r
106 The Configure() function is used to set, change, or reset the operational \r
107 parameters for the MNP child driver instance. Until the operational parameters\r
108 have been set, no network traffic can be sent or received by this MNP child\r
109 driver instance. Once the operational parameters have been reset, no more\r
110 traffic can be sent or received until the operational parameters have been set\r
111 again.\r
112 Each MNP child driver instance can be started and stopped independently of\r
113 each other by setting or resetting their receive filter settings with the\r
114 Configure() function.\r
115 After any successful call to Configure(), the MNP child driver instance is\r
116 started. The internal periodic timer (if supported) is enabled. Data can be\r
117 transmitted and may be received if the receive filters have also been enabled.\r
118 Note: If multiple MNP child driver instances will receive the same packet\r
119 because of overlapping receive filter settings, then the first MNP child\r
120 driver instance will receive the original packet and additional instances will\r
121 receive copies of the original packet.\r
122 Note: Warning: Receive filter settings that overlap will consume extra\r
123 processor and/or DMA resources and degrade system and network performance.\r
124\r
125 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
126 @param MnpConfigData Pointer to configuration data that will be assigned\r
127 to the MNP child driver instance. If NULL, the MNP\r
128 child driver instance is reset to startup defaults\r
129 and all pending transmit and receive requests are\r
130 flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is\r
131 defined in\r
132 EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().\r
8a67d61d 133\r
134 @retval EFI_SUCCESS The operation completed successfully.\r
b6c4ecad 135 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
136 TRUE:\r
137 * This is NULL.\r
138 * MnpConfigData.ProtocolTypeFilter is not\r
139 valid.\r
140 The operational data for the MNP child driver\r
141 instance is unchanged.\r
142 @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)\r
143 could not be allocated.\r
144 The MNP child driver instance has been reset to\r
145 startup defaults.\r
146 @retval EFI_UNSUPPORTED The requested feature is unsupported in\r
147 this [MNP] implementation. The operational data\r
148 for the MNP child driver instance is unchanged.\r
149 @retval EFI_DEVICE_ERROR An unexpected network or system error\r
150 occurred. The MNP child driver instance has\r
151 been reset to startup defaults.\r
8a67d61d 152 @retval Other The MNP child driver instance has been reset to\r
153 startup defaults.\r
154\r
155**/\r
156EFI_STATUS\r
157EFIAPI\r
158MnpConfigure (\r
159 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
160 IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL\r
161 )\r
162{\r
163 MNP_INSTANCE_DATA *Instance;\r
164 EFI_TPL OldTpl;\r
165 EFI_STATUS Status;\r
166\r
167 if ((This == NULL) ||\r
168 ((MnpConfigData != NULL) &&\r
169 (MnpConfigData->ProtocolTypeFilter > 0) &&\r
170 (MnpConfigData->ProtocolTypeFilter <= 1500))) {\r
171\r
172 return EFI_INVALID_PARAMETER;\r
173 }\r
174\r
175 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
176\r
e48e37fc 177 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 178\r
179 if ((MnpConfigData == NULL) && (!Instance->Configured)) {\r
180 //\r
181 // If the instance is not configured and a reset is requested, just return.\r
182 //\r
183 Status = EFI_SUCCESS;\r
184 goto ON_EXIT;\r
185 }\r
186\r
187 //\r
188 // Configure the instance.\r
189 //\r
190 Status = MnpConfigureInstance (Instance, MnpConfigData);\r
191\r
192ON_EXIT:\r
e48e37fc 193 gBS->RestoreTPL (OldTpl);\r
8a67d61d 194\r
195 return Status;\r
196}\r
197\r
198\r
199/**\r
b6c4ecad 200 Translates an IP multicast address to a hardware (MAC) multicast address. This \r
201 function may be unsupported in some MNP implementations. \r
202 \r
203 The McastIpToMac() function translates an IP multicast address to a hardware\r
204 (MAC) multicast address. This function may be implemented by calling the\r
205 underlying EFI_SIMPLE_NETWORK.MCastIpToMac() function, which may also be\r
206 unsupported in some MNP implementations.\r
207\r
208 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
209 @param Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.\r
210 Set to FALSE if IpAddress is an IPv4 multicast address.\r
211 @param IpAddress Pointer to the multicast IP address (in network byte order)\r
212 to convert.\r
213 @param MacAddress Pointer to the resulting multicast MAC address. \r
214\r
215 @retval EFI_SUCCESS The operation completed successfully.\r
216 @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r
217 * This is NULL.\r
218 * IpAddress is NULL.\r
219 * IpAddress is not a valid multicast IP\r
220 address.\r
221 * MacAddress is NULL.\r
222 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
223 configured.\r
224 @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r
225 MNP implementation.\r
226 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
227 @retval Other The address could not be converted.\r
8a67d61d 228**/\r
229EFI_STATUS\r
230EFIAPI\r
231MnpMcastIpToMac (\r
232 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
233 IN BOOLEAN Ipv6Flag,\r
234 IN EFI_IP_ADDRESS *IpAddress,\r
235 OUT EFI_MAC_ADDRESS *MacAddress\r
236 )\r
237{\r
238 EFI_STATUS Status;\r
239 MNP_INSTANCE_DATA *Instance;\r
240 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
241 EFI_TPL OldTpl;\r
242\r
243 if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
244\r
245 return EFI_INVALID_PARAMETER;\r
246 }\r
247\r
248 if (Ipv6Flag) {\r
249 //\r
250 // Currently IPv6 isn't supported.\r
251 //\r
252 return EFI_UNSUPPORTED;\r
253 }\r
254\r
255 if (!IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress))) {\r
256 //\r
257 // The IPv4 address passed in is not a multicast address.\r
258 //\r
259 return EFI_INVALID_PARAMETER;\r
260 }\r
261\r
262 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
263\r
e48e37fc 264 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 265\r
266 if (!Instance->Configured) {\r
267\r
268 Status = EFI_NOT_STARTED;\r
269 goto ON_EXIT;\r
270 }\r
271\r
272 Snp = Instance->MnpServiceData->Snp;\r
273 ASSERT (Snp != NULL);\r
274\r
275 if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
276 //\r
277 // Translate the IPv4 address into a multicast MAC address if the NIC is an\r
278 // ethernet NIC.\r
279 //\r
280 MacAddress->Addr[0] = 0x01;\r
281 MacAddress->Addr[1] = 0x00;\r
282 MacAddress->Addr[2] = 0x5E;\r
4eb65aff 283 MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);\r
8a67d61d 284 MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r
285 MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r
286\r
287 Status = EFI_SUCCESS;\r
288 } else {\r
289 //\r
290 // Invoke Snp to translate the multicast IP address.\r
291 //\r
292 Status = Snp->MCastIpToMac (\r
293 Snp,\r
294 Ipv6Flag,\r
295 IpAddress,\r
296 MacAddress\r
297 );\r
298 }\r
299\r
300ON_EXIT:\r
e48e37fc 301 gBS->RestoreTPL (OldTpl);\r
8a67d61d 302\r
303 return Status;\r
304}\r
305\r
8a67d61d 306/**\r
b6c4ecad 307 Enables and disables receive filters for multicast address. This function may \r
308 be unsupported in some MNP implementations.\r
309 \r
310 The Groups() function only adds and removes multicast MAC addresses from the \r
311 filter list. The MNP driver does not transmit or process Internet Group\r
312 Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r
313 NULL, then all joined groups are left.\r
314 \r
315 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
316 @param JoinFlag Set to TRUE to join this multicast group.\r
317 Set to FALSE to leave this multicast group.\r
318 @param MacAddress Pointer to the multicast MAC group (address) to join or\r
319 leave.\r
320\r
321 @retval EFI_SUCCESS The requested operation completed successfully.\r
322 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
323 * This is NULL.\r
324 * JoinFlag is TRUE and MacAddress is NULL.\r
325 * MacAddress is not a valid multicast MAC\r
326 address.\r
327 * The MNP multicast group settings are\r
328 unchanged.\r
329 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
330 configured.\r
331 @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.\r
332 @retval EFI_NOT_FOUND The supplied multicast group is not joined.\r
333 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
334 The MNP child driver instance has been reset to\r
335 startup defaults.\r
336 @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP\r
337 implementation.\r
338 @retval Other The requested operation could not be completed.\r
339 The MNP multicast group settings are unchanged.\r
8a67d61d 340\r
341**/\r
342EFI_STATUS\r
343EFIAPI\r
344MnpGroups (\r
345 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
346 IN BOOLEAN JoinFlag,\r
347 IN EFI_MAC_ADDRESS *MacAddress OPTIONAL\r
348 )\r
349{\r
350 MNP_INSTANCE_DATA *Instance;\r
351 EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
352 MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;\r
353 MNP_GROUP_ADDRESS *GroupAddress;\r
e48e37fc 354 LIST_ENTRY *ListEntry;\r
8a67d61d 355 BOOLEAN AddressExist;\r
356 EFI_TPL OldTpl;\r
357 EFI_STATUS Status;\r
358\r
359 if (This == NULL || (JoinFlag && (MacAddress == NULL))) {\r
360 //\r
361 // This is NULL, or it's a join operation but MacAddress is NULL.\r
362 //\r
363 return EFI_INVALID_PARAMETER;\r
364 }\r
365\r
366 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
367 SnpMode = Instance->MnpServiceData->Snp->Mode;\r
368\r
e48e37fc 369 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 370\r
371 if (!Instance->Configured) {\r
372\r
373 Status = EFI_NOT_STARTED;\r
374 goto ON_EXIT;\r
375 }\r
376\r
377 if ((!Instance->ConfigData.EnableMulticastReceive) ||\r
378 ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize))) {\r
379 //\r
380 // The instance isn't configured to do mulitcast receive. OR\r
381 // the passed in MacAddress is not a mutlticast mac address.\r
382 //\r
383 Status = EFI_INVALID_PARAMETER;\r
384 goto ON_EXIT;\r
385 }\r
386\r
387 Status = EFI_SUCCESS;\r
388 AddressExist = FALSE;\r
389 GroupCtrlBlk = NULL;\r
390\r
391 if (MacAddress != NULL) {\r
392 //\r
393 // Search the instance's GroupCtrlBlkList to find the specific address.\r
394 //\r
395 NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {\r
396\r
397 GroupCtrlBlk = NET_LIST_USER_STRUCT (\r
398 ListEntry,\r
399 MNP_GROUP_CONTROL_BLOCK,\r
400 CtrlBlkEntry\r
401 );\r
402 GroupAddress = GroupCtrlBlk->GroupAddress;\r
e48e37fc 403 if (0 == CompareMem (\r
8a67d61d 404 MacAddress,\r
405 &GroupAddress->Address,\r
406 SnpMode->HwAddressSize\r
407 )) {\r
408 //\r
409 // There is already the same multicast mac address configured.\r
410 //\r
411 AddressExist = TRUE;\r
412 break;\r
413 }\r
414 }\r
415\r
416 if (JoinFlag && AddressExist) {\r
417 //\r
418 // The multicast mac address to join already exists.\r
419 //\r
420 Status = EFI_ALREADY_STARTED;\r
421 }\r
422\r
423 if (!JoinFlag && !AddressExist) {\r
424 //\r
425 // The multicast mac address to leave doesn't exist in this instance.\r
426 //\r
427 Status = EFI_NOT_FOUND;\r
428 }\r
429\r
430 if (EFI_ERROR (Status)) {\r
431 goto ON_EXIT;\r
432 }\r
e48e37fc 433 } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {\r
8a67d61d 434 //\r
435 // The MacAddress is NULL and there is no configured multicast mac address,\r
436 // just return.\r
437 //\r
438 goto ON_EXIT;\r
439 }\r
440\r
441 //\r
442 // OK, it is time to take action.\r
443 //\r
444 Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);\r
445\r
446ON_EXIT:\r
e48e37fc 447 gBS->RestoreTPL (OldTpl);\r
8a67d61d 448\r
449 return Status;\r
450}\r
451\r
8a67d61d 452/**\r
b6c4ecad 453 Places asynchronous outgoing data packets into the transmit queue.\r
454 \r
455 The Transmit() function places a completion token into the transmit packet \r
456 queue. This function is always asynchronous.\r
457 The caller must fill in the Token.Event and Token.TxData fields in the\r
458 completion token, and these fields cannot be NULL. When the transmit operation\r
459 completes, the MNP updates the Token.Status field and the Token.Event is\r
460 signaled.\r
461 Note: There may be a performance penalty if the packet needs to be\r
462 defragmented before it can be transmitted by the network device. Systems in\r
463 which performance is critical should review the requirements and features of\r
464 the underlying communications device and drivers.\r
465 \r
466 \r
467 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
468 @param Token Pointer to a token associated with the transmit data\r
469 descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN is\r
470 defined in "Related Definitions" below.\r
471\r
472 @retval EFI_SUCCESS The transmit completion token was cached.\r
8a67d61d 473 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
474 configured.\r
b6c4ecad 475 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
476 TRUE:\r
477 * This is NULL.\r
478 * Token is NULL.\r
479 * Token.Event is NULL.\r
480 * Token.TxData is NULL.\r
481 * Token.TxData.DestinationAddress is not\r
482 NULL and Token.TxData.HeaderLength is zero.\r
483 * Token.TxData.FragmentCount is zero.\r
484 * (Token.TxData.HeaderLength +\r
485 Token.TxData.DataLength) is not equal to the\r
486 sum of the\r
487 Token.TxData.FragmentTable[].FragmentLength\r
488 fields.\r
489 * One or more of the\r
490 Token.TxData.FragmentTable[].FragmentLength\r
491 fields is zero.\r
492 * One or more of the\r
493 Token.TxData.FragmentTable[].FragmentBufferfields\r
494 is NULL.\r
495 * Token.TxData.DataLength is greater than MTU.\r
8a67d61d 496 @retval EFI_ACCESS_DENIED The transmit completion token is already in the\r
497 transmit queue.\r
498 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r
b6c4ecad 499 lack of system resources (usually memory). \r
8a67d61d 500 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
501 The MNP child driver instance has been reset to\r
502 startup defaults.\r
503 @retval EFI_NOT_READY The transmit request could not be queued because\r
504 the transmit queue is full.\r
505\r
506**/\r
507EFI_STATUS\r
508EFIAPI\r
509MnpTransmit (\r
510 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
511 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
512 )\r
513{\r
514 EFI_STATUS Status;\r
515 MNP_INSTANCE_DATA *Instance;\r
516 MNP_SERVICE_DATA *MnpServiceData;\r
517 UINT8 *PktBuf;\r
518 UINT32 PktLen;\r
519 EFI_TPL OldTpl;\r
520\r
521 if ((This == NULL) || (Token == NULL)) {\r
522\r
523 return EFI_INVALID_PARAMETER;\r
524 }\r
525\r
526 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
527\r
e48e37fc 528 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 529\r
530 if (!Instance->Configured) {\r
531\r
532 Status = EFI_NOT_STARTED;\r
533 goto ON_EXIT;\r
534 }\r
535\r
536 if (!MnpIsValidTxToken (Instance, Token)) {\r
537 //\r
538 // The Token is invalid.\r
539 //\r
540 Status = EFI_INVALID_PARAMETER;\r
541 goto ON_EXIT;\r
542 }\r
543\r
544 MnpServiceData = Instance->MnpServiceData;\r
545 NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
546\r
547 //\r
548 // Build the tx packet\r
549 //\r
550 MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r
551\r
552 //\r
553 // OK, send the packet synchronously.\r
554 //\r
555 Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);\r
556\r
557ON_EXIT:\r
e48e37fc 558 gBS->RestoreTPL (OldTpl);\r
8a67d61d 559\r
560 return Status;\r
561}\r
562\r
563\r
564/**\r
b6c4ecad 565 Places an asynchronous receiving request into the receiving queue.\r
566 \r
567 The Receive() function places a completion token into the receive packet \r
568 queue. This function is always asynchronous.\r
569 The caller must fill in the Token.Event field in the completion token, and\r
570 this field cannot be NULL. When the receive operation completes, the MNP\r
571 updates the Token.Status and Token.RxData fields and the Token.Event is\r
572 signaled.\r
573 \r
574 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
575 @param Token Pointer to a token associated with the receive\r
576 data descriptor. Type\r
577 EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r
578 EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r
8a67d61d 579\r
580 @retval EFI_SUCCESS The receive completion token was cached.\r
581 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
582 configured.\r
b6c4ecad 583 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
584 TRUE:\r
585 * This is NULL.\r
586 * Token is NULL.\r
587 * Token.Event is NULL\r
8a67d61d 588 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r
589 lack of system resources (usually memory).\r
590 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
591 The MNP child driver instance has been reset to\r
592 startup defaults.\r
593 @retval EFI_ACCESS_DENIED The receive completion token was already in the\r
594 receive queue.\r
595 @retval EFI_NOT_READY The receive request could not be queued because\r
596 the receive queue is full.\r
597\r
598**/\r
599EFI_STATUS\r
600EFIAPI\r
601MnpReceive (\r
602 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
603 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
604 )\r
605{\r
606 EFI_STATUS Status;\r
607 MNP_INSTANCE_DATA *Instance;\r
608 EFI_TPL OldTpl;\r
609\r
610 if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r
611\r
612 return EFI_INVALID_PARAMETER;\r
613 }\r
614\r
615 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
616\r
e48e37fc 617 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 618\r
619 if (!Instance->Configured) {\r
620\r
621 Status = EFI_NOT_STARTED;\r
622 goto ON_EXIT;\r
623 }\r
624\r
625 //\r
626 // Check whether this token(event) is already in the rx token queue.\r
627 //\r
628 Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);\r
629 if (EFI_ERROR (Status)) {\r
630\r
631 goto ON_EXIT;\r
632 }\r
633\r
634 //\r
635 // Insert the Token into the RxTokenMap.\r
636 //\r
637 Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);\r
638\r
639 if (!EFI_ERROR (Status)) {\r
640 //\r
641 // Try to deliver any buffered packets.\r
642 //\r
643 Status = MnpInstanceDeliverPacket (Instance);\r
36ee91ca 644\r
645 //\r
646 // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
647 //\r
648 NetLibDispatchDpc ();\r
8a67d61d 649 }\r
650\r
651ON_EXIT:\r
e48e37fc 652 gBS->RestoreTPL (OldTpl);\r
8a67d61d 653\r
654 return Status;\r
655}\r
656\r
8a67d61d 657/**\r
b6c4ecad 658 Aborts an asynchronous transmit or receive request. \r
659 \r
660 The Cancel() function is used to abort a pending transmit or receive request.\r
661 If the token is in the transmit or receive request queues, after calling this\r
662 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
663 signaled. If the token is not in one of the queues, which usually means that\r
664 the asynchronous operation has completed, this function will not signal the\r
665 token and EFI_NOT_FOUND is returned.\r
666\r
667 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
668 @param Token Pointer to a token that has been issued by\r
669 EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r
670 EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all pending\r
671 tokens are aborted.\r
8a67d61d 672\r
673 @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r
b6c4ecad 674 Token.Event was signaled. When Token is NULL,\r
675 all pending requests were aborted and their\r
676 events were signaled.\r
8a67d61d 677 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
678 configured.\r
679 @retval EFI_INVALID_PARAMETER This is NULL.\r
b6c4ecad 680 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O\r
681 request was not found in the transmit or\r
682 receive queue. It has either completed or was\r
683 not issued by Transmit() and Receive().\r
8a67d61d 684\r
685**/\r
686EFI_STATUS\r
687EFIAPI\r
688MnpCancel (\r
689 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
690 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL\r
691 )\r
692{\r
693 EFI_STATUS Status;\r
694 MNP_INSTANCE_DATA *Instance;\r
695 EFI_TPL OldTpl;\r
696\r
697 if (This == NULL) {\r
698\r
699 return EFI_INVALID_PARAMETER;\r
700 }\r
701\r
702 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
703\r
e48e37fc 704 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 705\r
706 if (!Instance->Configured) {\r
707\r
708 Status = EFI_NOT_STARTED;\r
709 goto ON_EXIT;\r
710 }\r
711\r
712 //\r
713 // Iterate the RxTokenMap to cancel the specified Token.\r
714 //\r
715 Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);\r
716\r
717 if (Token != NULL) {\r
718\r
719 Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
720 }\r
721\r
36ee91ca 722 //\r
723 // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.\r
724 //\r
725 NetLibDispatchDpc ();\r
726\r
8a67d61d 727ON_EXIT:\r
e48e37fc 728 gBS->RestoreTPL (OldTpl);\r
8a67d61d 729\r
730 return Status;\r
731}\r
732\r
8a67d61d 733/**\r
b6c4ecad 734 Polls for incoming data packets and processes outgoing data packets. \r
735 \r
736 The Poll() function can be used by network drivers and applications to \r
737 increase the rate that data packets are moved between the communications\r
738 device and the transmit and receive queues.\r
739 Normally, a periodic timer event internally calls the Poll() function. But, in\r
740 some systems, the periodic timer event may not call Poll() fast enough to\r
741 transmit and/or receive all data packets without missing packets. Drivers and\r
742 applications that are experiencing packet loss should try calling the Poll()\r
743 function more often.\r
744\r
745 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
746\r
747 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
748 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
749 configured.\r
750 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The\r
751 MNP child driver instance has been reset to startup\r
752 defaults.\r
753 @retval EFI_NOT_READY No incoming or outgoing data was processed. Consider\r
754 increasing the polling rate.\r
755 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive\r
756 queue. Consider increasing the polling rate.\r
8a67d61d 757\r
758**/\r
759EFI_STATUS\r
760EFIAPI\r
761MnpPoll (\r
762 IN EFI_MANAGED_NETWORK_PROTOCOL *This\r
763 )\r
764{\r
765 EFI_STATUS Status;\r
766 MNP_INSTANCE_DATA *Instance;\r
767 EFI_TPL OldTpl;\r
768\r
769 if (This == NULL) {\r
770 return EFI_INVALID_PARAMETER;\r
771 }\r
772\r
773 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
774\r
e48e37fc 775 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 776\r
777 if (!Instance->Configured) {\r
778 Status = EFI_NOT_STARTED;\r
779 goto ON_EXIT;\r
780 }\r
781\r
782 //\r
783 // Try to receive packets.\r
784 //\r
785 Status = MnpReceivePacket (Instance->MnpServiceData);\r
786\r
36ee91ca 787 NetLibDispatchDpc ();\r
788\r
8a67d61d 789ON_EXIT:\r
e48e37fc 790 gBS->RestoreTPL (OldTpl);\r
8a67d61d 791\r
792 return Status;\r
793}\r
36ee91ca 794\r