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