]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioNetDxe/SnpReceiveFilters.c
ShellPkg/for: Fix potential null pointer deference
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / SnpReceiveFilters.c
CommitLineData
1771d0a1
LE
1/** @file\r
2\r
3 Implementation of the SNP.ReceiveFilters() function and its private helpers\r
4 if any.\r
5\r
6 Copyright (C) 2013, Red Hat, Inc.\r
7 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
8\r
9 This program and the accompanying materials are licensed and made available\r
10 under the terms and conditions of the BSD License which accompanies this\r
11 distribution. The full text of the license may be found at\r
12 http://opensource.org/licenses/bsd-license.php\r
13\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
15 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#include <Library/UefiBootServicesTableLib.h>\r
20\r
21#include "VirtioNet.h"\r
22\r
23/**\r
24 Manages the multicast receive filters of a network interface.\r
25\r
26 @param This The protocol instance pointer.\r
27 @param Enable A bit mask of receive filters to enable on the\r
28 network interface.\r
29 @param Disable A bit mask of receive filters to disable on the\r
30 network interface.\r
31 @param ResetMCastFilter Set to TRUE to reset the contents of the multicast\r
32 receive filters on the network interface to their\r
33 default values.\r
34 @param McastFilterCnt Number of multicast HW MAC addresses in the new\r
35 MCastFilter list. This value must be less than or\r
36 equal to the MCastFilterCnt field of\r
37 EFI_SIMPLE_NETWORK_MODE. This field is optional if\r
38 ResetMCastFilter is TRUE.\r
39 @param MCastFilter A pointer to a list of new multicast receive filter\r
40 HW MAC addresses. This list will replace any\r
41 existing multicast HW MAC address list. This field\r
42 is optional if ResetMCastFilter is TRUE.\r
43\r
44 @retval EFI_SUCCESS The multicast receive filter list was updated.\r
45 @retval EFI_NOT_STARTED The network interface has not been started.\r
46 @retval EFI_INVALID_PARAMETER One or more of the parameters has an\r
47 unsupported value.\r
48 @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
49 interface.\r
50 @retval EFI_UNSUPPORTED This function is not supported by the network\r
51 interface.\r
52\r
53**/\r
54\r
55EFI_STATUS\r
56EFIAPI\r
57VirtioNetReceiveFilters (\r
58 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
59 IN UINT32 Enable,\r
60 IN UINT32 Disable,\r
61 IN BOOLEAN ResetMCastFilter,\r
62 IN UINTN MCastFilterCnt OPTIONAL,\r
63 IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL\r
64 )\r
65{\r
66 VNET_DEV *Dev;\r
67 EFI_TPL OldTpl;\r
68 EFI_STATUS Status;\r
69\r
70 if (This == NULL) {\r
71 return EFI_INVALID_PARAMETER;\r
72 }\r
73\r
74 Dev = VIRTIO_NET_FROM_SNP (This);\r
75 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
76 switch (Dev->Snm.State) {\r
77 case EfiSimpleNetworkStopped:\r
78 Status = EFI_NOT_STARTED;\r
79 goto Exit;\r
80 case EfiSimpleNetworkStarted:\r
81 Status = EFI_DEVICE_ERROR;\r
82 goto Exit;\r
83 default:\r
84 break;\r
85 }\r
86\r
87 //\r
88 // MNP apparently fails to initialize on top of us if we simply return\r
89 // EFI_UNSUPPORTED in this function.\r
90 //\r
91 // Hence we openly refuse multicast functionality, and fake the rest by\r
92 // selecting a no stricter filter setting than whatever is requested. The\r
93 // UEFI-2.3.1+errC spec allows this. In practice we don't change our current\r
94 // (default) filter. Additionally, receiving software is responsible for\r
95 // discarding any packets getting through the filter.\r
96 //\r
97 Status = (\r
98 ((Enable | Disable) & ~Dev->Snm.ReceiveFilterMask) != 0 ||\r
99 (!ResetMCastFilter && MCastFilterCnt > Dev->Snm.MaxMCastFilterCount)\r
100 ) ? EFI_INVALID_PARAMETER : EFI_SUCCESS;\r
101\r
102Exit:\r
103 gBS->RestoreTPL (OldTpl);\r
104 return Status;\r
105}\r