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