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