sync comments, fix function header, rename variable name to follow coding style.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Mcast_ip_to_mac.c
1 /** @file
2 Implementation of converting an multicast IP address to multicast HW MAC
3 address.
4
5 Copyright (c) 2004 - 2007, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials are licensed
7 and made available under the terms and conditions of the BSD License which
8 accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "Snp.h"
17
18 /**
19 this routine calls undi to convert an multicast IP address to a MAC address.
20
21 @param Snp pointer to snp driver structure
22 @param IPv6 flag to indicate if this is an ipv6 address
23 @param IP multicast IP address
24 @param MAC pointer to hold the return MAC address
25
26
27 **/
28 EFI_STATUS
29 PxeIp2Mac (
30 IN SNP_DRIVER *Snp,
31 IN BOOLEAN IPv6,
32 IN EFI_IP_ADDRESS *IP,
33 IN OUT EFI_MAC_ADDRESS *MAC
34 )
35 {
36 PXE_CPB_MCAST_IP_TO_MAC *Cpb;
37 PXE_DB_MCAST_IP_TO_MAC *Db;
38
39 Cpb = Snp->Cpb;
40 Db = Snp->Db;
41 Snp->Cdb.OpCode = PXE_OPCODE_MCAST_IP_TO_MAC;
42 Snp->Cdb.OpFlags = (UINT16) (IPv6 ? PXE_OPFLAGS_MCAST_IPV6_TO_MAC : PXE_OPFLAGS_MCAST_IPV4_TO_MAC);
43 Snp->Cdb.CPBsize = sizeof (PXE_CPB_MCAST_IP_TO_MAC);
44 Snp->Cdb.DBsize = sizeof (PXE_DB_MCAST_IP_TO_MAC);
45
46 Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;
47 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
48
49 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
50 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
51 Snp->Cdb.IFnum = Snp->IfNum;
52 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
53
54 CopyMem (&Cpb->IP, IP, sizeof (PXE_IP_ADDR));
55
56 //
57 // Issue UNDI command and check result.
58 //
59 DEBUG ((EFI_D_NET, "\nSnp->undi.mcast_ip_to_mac() "));
60
61 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
62
63 switch (Snp->Cdb.StatCode) {
64 case PXE_STATCODE_SUCCESS:
65 break;
66
67 case PXE_STATCODE_INVALID_CPB:
68 return EFI_INVALID_PARAMETER;
69
70 case PXE_STATCODE_UNSUPPORTED:
71 DEBUG (
72 (EFI_D_NET,
73 "\nSnp->undi.mcast_ip_to_mac() %xh:%xh\n",
74 Snp->Cdb.StatFlags,
75 Snp->Cdb.StatCode)
76 );
77 return EFI_UNSUPPORTED;
78
79 default:
80 //
81 // UNDI command failed. Return EFI_DEVICE_ERROR
82 // to caller.
83 //
84 DEBUG (
85 (EFI_D_NET,
86 "\nSnp->undi.mcast_ip_to_mac() %xh:%xh\n",
87 Snp->Cdb.StatFlags,
88 Snp->Cdb.StatCode)
89 );
90
91 return EFI_DEVICE_ERROR;
92 }
93
94 CopyMem (MAC, &Db->MAC, sizeof (PXE_MAC_ADDR));
95 return EFI_SUCCESS;
96 }
97
98
99 /**
100 Converts a multicast IP address to a multicast HW MAC address.
101
102 This function converts a multicast IP address to a multicast HW MAC address
103 for all packet transactions. If the mapping is accepted, then EFI_SUCCESS will
104 be returned.
105
106 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
107 @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460].
108 Set to FALSE if the multicast IP address is IPv4 [RFC 791].
109 @param IP The multicast IP address that is to be converted to a multicast
110 HW MAC address.
111 @param MAC The multicast HW MAC address that is to be generated from IP.
112
113 @retval EFI_SUCCESS The multicast IP address was mapped to the
114 multicast HW MAC address.
115 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not
116 been started by calling Start().
117 @retval EFI_INVALID_PARAMETER IP is NULL.
118 @retval EFI_INVALID_PARAMETER MAC is NULL.
119 @retval EFI_INVALID_PARAMETER IP does not point to a valid IPv4 or IPv6
120 multicast address.
121 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
122 been initialized by calling Initialize().
123 @retval EFI_UNSUPPORTED IPv6 is TRUE and the implementation does not
124 support IPv6 multicast to MAC address conversion.
125
126 **/
127 EFI_STATUS
128 EFIAPI
129 SnpUndi32McastIpToMac (
130 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
131 IN BOOLEAN IPv6,
132 IN EFI_IP_ADDRESS *IP,
133 OUT EFI_MAC_ADDRESS *MAC
134 )
135 {
136 SNP_DRIVER *Snp;
137 EFI_TPL OldTpl;
138 EFI_STATUS Status;
139
140 //
141 // Get pointer to SNP driver instance for *this.
142 //
143 if (This == NULL) {
144 return EFI_INVALID_PARAMETER;
145 }
146
147 if (IP == NULL || MAC == NULL) {
148 return EFI_INVALID_PARAMETER;
149 }
150
151 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
152
153 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
154
155 switch (Snp->Mode.State) {
156 case EfiSimpleNetworkInitialized:
157 break;
158
159 case EfiSimpleNetworkStopped:
160 Status = EFI_NOT_STARTED;
161 goto ON_EXIT;
162
163 default:
164 Status = EFI_DEVICE_ERROR;
165 goto ON_EXIT;
166 }
167
168 Status = PxeIp2Mac (Snp, IPv6, IP, MAC);
169
170 ON_EXIT:
171 gBS->RestoreTPL (OldTpl);
172
173 return Status;
174 }