]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Mcast_ip_to_mac.c
91b5e02fc1974a8d1fbc9687999f443399febc21
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Mcast_ip_to_mac.c
1 /** @file
2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module name:
12 mcast_ip_to_mac.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-17 M(f)J Genesis.
18
19 **/
20
21 #include "Snp.h"
22
23 /**
24 this routine calls undi to convert an multicast IP address to a MAC address
25
26 @param snp pointer to snp driver structure
27 @param IPv6 flag to indicate if this is an ipv6 address
28 @param IP multicast IP address
29 @param MAC pointer to hold the return MAC address
30
31
32 **/
33 STATIC
34 EFI_STATUS
35 pxe_ip2mac (
36 IN SNP_DRIVER *snp,
37 IN BOOLEAN IPv6,
38 IN EFI_IP_ADDRESS *IP,
39 IN OUT EFI_MAC_ADDRESS *MAC
40 )
41 {
42 PXE_CPB_MCAST_IP_TO_MAC *cpb;
43 PXE_DB_MCAST_IP_TO_MAC *db;
44
45 cpb = snp->cpb;
46 db = snp->db;
47 snp->cdb.OpCode = PXE_OPCODE_MCAST_IP_TO_MAC;
48 snp->cdb.OpFlags = (UINT16) (IPv6 ? PXE_OPFLAGS_MCAST_IPV6_TO_MAC : PXE_OPFLAGS_MCAST_IPV4_TO_MAC);
49 snp->cdb.CPBsize = sizeof (PXE_CPB_MCAST_IP_TO_MAC);
50 snp->cdb.DBsize = sizeof (PXE_DB_MCAST_IP_TO_MAC);
51
52 snp->cdb.CPBaddr = (UINT64)(UINTN) cpb;
53 snp->cdb.DBaddr = (UINT64)(UINTN) db;
54
55 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;
56 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
57 snp->cdb.IFnum = snp->if_num;
58 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
59
60 CopyMem (&cpb->IP, IP, sizeof (PXE_IP_ADDR));
61
62 //
63 // Issue UNDI command and check result.
64 //
65 DEBUG ((EFI_D_NET, "\nsnp->undi.mcast_ip_to_mac() "));
66
67 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
68
69 switch (snp->cdb.StatCode) {
70 case PXE_STATCODE_SUCCESS:
71 break;
72
73 case PXE_STATCODE_INVALID_CPB:
74 return EFI_INVALID_PARAMETER;
75
76 case PXE_STATCODE_UNSUPPORTED:
77 DEBUG (
78 (EFI_D_NET,
79 "\nsnp->undi.mcast_ip_to_mac() %xh:%xh\n",
80 snp->cdb.StatFlags,
81 snp->cdb.StatCode)
82 );
83 return EFI_UNSUPPORTED;
84
85 default:
86 //
87 // UNDI command failed. Return EFI_DEVICE_ERROR
88 // to caller.
89 //
90 DEBUG (
91 (EFI_D_NET,
92 "\nsnp->undi.mcast_ip_to_mac() %xh:%xh\n",
93 snp->cdb.StatFlags,
94 snp->cdb.StatCode)
95 );
96
97 return EFI_DEVICE_ERROR;
98 }
99
100 CopyMem (MAC, &db->MAC, sizeof (PXE_MAC_ADDR));
101 return EFI_SUCCESS;
102 }
103
104
105 /**
106 This is the SNP interface routine for converting a multicast IP address to
107 a MAC address.
108 This routine basically retrieves snp structure, checks the SNP state and
109 calls the pxe_ip2mac routine to actually do the conversion
110
111 @param this context pointer
112 @param IPv6 flag to indicate if this is an ipv6 address
113 @param IP multicast IP address
114 @param MAC pointer to hold the return MAC address
115
116
117 **/
118 EFI_STATUS
119 EFIAPI
120 snp_undi32_mcast_ip_to_mac (
121 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
122 IN BOOLEAN IPv6,
123 IN EFI_IP_ADDRESS *IP,
124 OUT EFI_MAC_ADDRESS *MAC
125 )
126 {
127 SNP_DRIVER *snp;
128 EFI_TPL OldTpl;
129 EFI_STATUS Status;
130
131 //
132 // Get pointer to SNP driver instance for *this.
133 //
134 if (this == NULL) {
135 return EFI_INVALID_PARAMETER;
136 }
137
138 if (IP == NULL || MAC == NULL) {
139 return EFI_INVALID_PARAMETER;
140 }
141
142 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
143
144 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
145
146 switch (snp->mode.State) {
147 case EfiSimpleNetworkInitialized:
148 break;
149
150 case EfiSimpleNetworkStopped:
151 Status = EFI_NOT_STARTED;
152 goto ON_EXIT;
153
154 default:
155 Status = EFI_DEVICE_ERROR;
156 goto ON_EXIT;
157 }
158
159 Status = pxe_ip2mac (snp, IPv6, IP, MAC);
160
161 ON_EXIT:
162 gBS->RestoreTPL (OldTpl);
163
164 return Status;
165 }