]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
IntelFsp2Pkg SecFspSecPlatformLibNull: Remove MASM/GAS files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcSupport.c
CommitLineData
dc361cc5 1/** @file\r
f737cfb9 2 Support routines for PxeBc.\r
e2851998 3\r
60de3c19 4Copyright (c) 2007 - 2016, 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
60de3c19
FS
45 @param TTL The time to live field of the IP header. \r
46 @param ToS The type of service field of the IP header.\r
e2851998 47\r
f737cfb9 48 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.\r
49 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,\r
50 RARP, etc.) is not finished yet.\r
51 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
52 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured\r
53 and must be stopped/reset before it can be reconfigured.\r
54 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE\r
55 and UdpConfigData.StationPort is already used by\r
56 other instance.\r
57 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this\r
58 EFI UDPv4 Protocol instance.\r
59 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance\r
60 was not opened.\r
61 @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.\r
e2851998 62\r
f737cfb9 63**/\r
8792362f 64EFI_STATUS\r
65PxeBcConfigureUdpWriteInstance (\r
66 IN EFI_UDP4_PROTOCOL *Udp4,\r
67 IN EFI_IPv4_ADDRESS *StationIp,\r
68 IN EFI_IPv4_ADDRESS *SubnetMask,\r
69 IN EFI_IPv4_ADDRESS *Gateway,\r
60de3c19
FS
70 IN OUT UINT16 *SrcPort,\r
71 IN UINT8 TTL,\r
72 IN UINT8 ToS\r
8792362f 73 )\r
74{\r
75 EFI_UDP4_CONFIG_DATA Udp4CfgData;\r
76 EFI_STATUS Status;\r
77\r
78 ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
79\r
7bc01e86 80 Udp4CfgData.ReceiveTimeout = PXEBC_DEFAULT_LIFETIME;\r
60de3c19
FS
81 Udp4CfgData.TypeOfService = ToS;\r
82 Udp4CfgData.TimeToLive = TTL;\r
319075ff 83 Udp4CfgData.AllowDuplicatePort = TRUE;\r
8792362f 84\r
85 CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
86 CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r
87\r
88 Udp4CfgData.StationPort = *SrcPort;\r
89\r
90 //\r
91 // Reset the instance.\r
92 //\r
93 Udp4->Configure (Udp4, NULL);\r
94\r
95 Status = Udp4->Configure (Udp4, &Udp4CfgData);\r
96 if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r
97 //\r
98 // basic configuration OK, need to add the default route entry\r
99 //\r
100 Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r
101 if (EFI_ERROR (Status)) {\r
102 //\r
103 // roll back\r
104 //\r
105 Udp4->Configure (Udp4, NULL);\r
106 }\r
107 }\r
108\r
109 if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r
110 Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r
111 *SrcPort = Udp4CfgData.StationPort;\r
112 }\r
113\r
114 return Status;\r
115}\r
116\r
dc361cc5 117\r
118/**\r
f737cfb9 119 Convert number to ASCII value.\r
dc361cc5 120\r
121 @param Number Numeric value to convert to decimal ASCII value.\r
f737cfb9 122 @param Buffer Buffer to place ASCII version of the Number.\r
dc361cc5 123 @param Length Length of Buffer.\r
124\r
dc361cc5 125**/\r
126VOID\r
127CvtNum (\r
128 IN UINTN Number,\r
129 IN UINT8 *Buffer,\r
f737cfb9 130 IN UINTN Length\r
dc361cc5 131 )\r
132{\r
133 UINTN Remainder;\r
134\r
894d038a 135 while (Length > 0) {\r
dc361cc5 136 Remainder = Number % 10;\r
137 Number /= 10;\r
894d038a 138 Length--;\r
dc361cc5 139 Buffer[Length] = (UINT8) ('0' + Remainder);\r
140 }\r
141}\r
142\r
143\r
144/**\r
f737cfb9 145 Convert unsigned int number to decimal number.\r
dc361cc5 146\r
206b5f51
ZL
147 @param Number The unsigned int number will be converted.\r
148 @param Buffer Pointer to the buffer to store the decimal number after transform.\r
149 @param[in] BufferSize The maxsize of the buffer.\r
150 \r
f737cfb9 151 @return the length of the number after transform.\r
dc361cc5 152\r
153**/\r
154UINTN\r
155UtoA10 (\r
156 IN UINTN Number,\r
206b5f51
ZL
157 IN CHAR8 *Buffer,\r
158 IN UINTN BufferSize\r
dc361cc5 159 )\r
160{\r
161 UINTN Index;\r
162 CHAR8 TempStr[64];\r
163\r
164 Index = 63;\r
165 TempStr[Index] = 0;\r
166\r
167 do {\r
168 Index--;\r
169 TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r
170 Number = Number / 10;\r
171 } while (Number != 0);\r
172\r
206b5f51 173 AsciiStrCpyS (Buffer, BufferSize, &TempStr[Index]);\r
dc361cc5 174\r
175 return AsciiStrLen (Buffer);\r
176}\r
177\r
178\r
179/**\r
f737cfb9 180 Convert ASCII numeric string to a UINTN value.\r
dc361cc5 181\r
f737cfb9 182 @param Buffer Pointer to the 8-byte unsigned int value.\r
dc361cc5 183\r
f737cfb9 184 @return UINTN value of the ASCII string.\r
dc361cc5 185\r
186**/\r
187UINT64\r
188AtoU64 (\r
189 IN UINT8 *Buffer\r
190 )\r
191{\r
192 UINT64 Value;\r
193 UINT8 Character;\r
194\r
195 Value = 0;\r
196 while ((Character = *Buffer++) != '\0') {\r
197 Value = MultU64x32 (Value, 10) + (Character - '0');\r
198 }\r
199\r
200 return Value;\r
201}\r
202\r