]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
Fix a bug for vlan ping failure.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcSupport.c
CommitLineData
dc361cc5 1/** @file\r
f737cfb9 2 Support routines for PxeBc.\r
e2851998 3\r
57b301b5 4Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
dc361cc5 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
dc361cc5 13**/\r
14\r
15\r
16#include "PxeBcImpl.h"\r
17\r
18\r
dc361cc5 19/**\r
e2851998 20 The common notify function associated with various PxeBc events.\r
dc361cc5 21\r
f737cfb9 22 @param Event The event signaled.\r
23 @param Context The context.\r
dc361cc5 24\r
dc361cc5 25**/\r
26VOID\r
6d3ea23f 27EFIAPI\r
dc361cc5 28PxeBcCommonNotify (\r
29 IN EFI_EVENT Event,\r
30 IN VOID *Context\r
31 )\r
32{\r
33 *((BOOLEAN *) Context) = TRUE;\r
34}\r
35\r
f737cfb9 36\r
37/**\r
38 This function initialize(or configure) the Udp4Write instance.\r
e2851998 39\r
f737cfb9 40 @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.\r
41 @param StationIp Pointer to the station ip address.\r
42 @param SubnetMask Pointer to the subnetmask of the station ip address.\r
43 @param Gateway Pointer to the gateway ip address.\r
44 @param SrcPort Pointer to the srouce port of the station.\r
e2851998 45\r
f737cfb9 46 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.\r
47 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,\r
48 RARP, etc.) is not finished yet.\r
49 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
50 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured\r
51 and must be stopped/reset before it can be reconfigured.\r
52 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE\r
53 and UdpConfigData.StationPort is already used by\r
54 other instance.\r
55 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this\r
56 EFI UDPv4 Protocol instance.\r
57 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance\r
58 was not opened.\r
59 @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.\r
e2851998 60\r
f737cfb9 61**/\r
8792362f 62EFI_STATUS\r
63PxeBcConfigureUdpWriteInstance (\r
64 IN EFI_UDP4_PROTOCOL *Udp4,\r
65 IN EFI_IPv4_ADDRESS *StationIp,\r
66 IN EFI_IPv4_ADDRESS *SubnetMask,\r
67 IN EFI_IPv4_ADDRESS *Gateway,\r
68 IN OUT UINT16 *SrcPort\r
69 )\r
70{\r
71 EFI_UDP4_CONFIG_DATA Udp4CfgData;\r
72 EFI_STATUS Status;\r
73\r
74 ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
75\r
7bc01e86 76 Udp4CfgData.ReceiveTimeout = PXEBC_DEFAULT_LIFETIME;\r
8792362f 77 Udp4CfgData.TypeOfService = DEFAULT_ToS;\r
78 Udp4CfgData.TimeToLive = DEFAULT_TTL;\r
319075ff 79 Udp4CfgData.AllowDuplicatePort = TRUE;\r
8792362f 80\r
81 CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
82 CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r
83\r
84 Udp4CfgData.StationPort = *SrcPort;\r
85\r
86 //\r
87 // Reset the instance.\r
88 //\r
89 Udp4->Configure (Udp4, NULL);\r
90\r
91 Status = Udp4->Configure (Udp4, &Udp4CfgData);\r
92 if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r
93 //\r
94 // basic configuration OK, need to add the default route entry\r
95 //\r
96 Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r
97 if (EFI_ERROR (Status)) {\r
98 //\r
99 // roll back\r
100 //\r
101 Udp4->Configure (Udp4, NULL);\r
102 }\r
103 }\r
104\r
105 if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r
106 Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r
107 *SrcPort = Udp4CfgData.StationPort;\r
108 }\r
109\r
110 return Status;\r
111}\r
112\r
dc361cc5 113\r
114/**\r
f737cfb9 115 Convert number to ASCII value.\r
dc361cc5 116\r
117 @param Number Numeric value to convert to decimal ASCII value.\r
f737cfb9 118 @param Buffer Buffer to place ASCII version of the Number.\r
dc361cc5 119 @param Length Length of Buffer.\r
120\r
dc361cc5 121**/\r
122VOID\r
123CvtNum (\r
124 IN UINTN Number,\r
125 IN UINT8 *Buffer,\r
f737cfb9 126 IN UINTN Length\r
dc361cc5 127 )\r
128{\r
129 UINTN Remainder;\r
130\r
894d038a 131 while (Length > 0) {\r
dc361cc5 132 Remainder = Number % 10;\r
133 Number /= 10;\r
894d038a 134 Length--;\r
dc361cc5 135 Buffer[Length] = (UINT8) ('0' + Remainder);\r
136 }\r
137}\r
138\r
139\r
140/**\r
f737cfb9 141 Convert unsigned int number to decimal number.\r
dc361cc5 142\r
f737cfb9 143 @param Number The unsigned int number will be converted.\r
144 @param Buffer Pointer to the buffer to store the decimal number after transform.\r
dc361cc5 145\r
f737cfb9 146 @return the length of the number after transform.\r
dc361cc5 147\r
148**/\r
149UINTN\r
150UtoA10 (\r
151 IN UINTN Number,\r
152 IN CHAR8 *Buffer\r
153 )\r
154{\r
155 UINTN Index;\r
156 CHAR8 TempStr[64];\r
157\r
158 Index = 63;\r
159 TempStr[Index] = 0;\r
160\r
161 do {\r
162 Index--;\r
163 TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r
164 Number = Number / 10;\r
165 } while (Number != 0);\r
166\r
167 AsciiStrCpy (Buffer, &TempStr[Index]);\r
168\r
169 return AsciiStrLen (Buffer);\r
170}\r
171\r
172\r
173/**\r
f737cfb9 174 Convert ASCII numeric string to a UINTN value.\r
dc361cc5 175\r
f737cfb9 176 @param Buffer Pointer to the 8-byte unsigned int value.\r
dc361cc5 177\r
f737cfb9 178 @return UINTN value of the ASCII string.\r
dc361cc5 179\r
180**/\r
181UINT64\r
182AtoU64 (\r
183 IN UINT8 *Buffer\r
184 )\r
185{\r
186 UINT64 Value;\r
187 UINT8 Character;\r
188\r
189 Value = 0;\r
190 while ((Character = *Buffer++) != '\0') {\r
191 Value = MultU64x32 (Value, 10) + (Character - '0');\r
192 }\r
193\r
194 return Value;\r
195}\r
196\r