]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
MdeModulePkg: Clean up source 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
d1102dba 4Copyright (c) 2007 - 2018, 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
d1102dba 45 @param Ttl The time to live field of the IP header.\r
60de3c19 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 70 IN OUT UINT16 *SrcPort,\r
0a28d02d 71 IN UINT8 Ttl,\r
60de3c19 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 81 Udp4CfgData.TypeOfService = ToS;\r
c882bdc6 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
52250844
JW
117/**\r
118 This function is to display the IPv4 address.\r
119\r
120 @param[in] Ip The pointer to the IPv4 address.\r
121\r
122**/\r
123VOID\r
124PxeBcShowIp4Addr (\r
125 IN EFI_IPv4_ADDRESS *Ip\r
126 )\r
127{\r
128 UINTN Index;\r
129\r
130 for (Index = 0; Index < 4; Index++) {\r
131 AsciiPrint ("%d", Ip->Addr[Index]);\r
132 if (Index < 3) {\r
133 AsciiPrint (".");\r
134 }\r
135 }\r
136}\r
dc361cc5 137\r
138/**\r
f737cfb9 139 Convert number to ASCII value.\r
dc361cc5 140\r
141 @param Number Numeric value to convert to decimal ASCII value.\r
f737cfb9 142 @param Buffer Buffer to place ASCII version of the Number.\r
dc361cc5 143 @param Length Length of Buffer.\r
144\r
dc361cc5 145**/\r
146VOID\r
147CvtNum (\r
148 IN UINTN Number,\r
149 IN UINT8 *Buffer,\r
f737cfb9 150 IN UINTN Length\r
dc361cc5 151 )\r
152{\r
153 UINTN Remainder;\r
154\r
81a10843 155 for (; Length > 0; Length--) {\r
dc361cc5 156 Remainder = Number % 10;\r
157 Number /= 10;\r
81a10843 158 Buffer[Length - 1] = (UINT8) ('0' + Remainder);\r
dc361cc5 159 }\r
160}\r
161\r
162\r
163/**\r
f737cfb9 164 Convert unsigned int number to decimal number.\r
dc361cc5 165\r
206b5f51
ZL
166 @param Number The unsigned int number will be converted.\r
167 @param Buffer Pointer to the buffer to store the decimal number after transform.\r
168 @param[in] BufferSize The maxsize of the buffer.\r
d1102dba 169\r
f737cfb9 170 @return the length of the number after transform.\r
dc361cc5 171\r
172**/\r
173UINTN\r
174UtoA10 (\r
175 IN UINTN Number,\r
206b5f51
ZL
176 IN CHAR8 *Buffer,\r
177 IN UINTN BufferSize\r
dc361cc5 178 )\r
179{\r
180 UINTN Index;\r
181 CHAR8 TempStr[64];\r
182\r
183 Index = 63;\r
184 TempStr[Index] = 0;\r
185\r
186 do {\r
187 Index--;\r
188 TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r
189 Number = Number / 10;\r
190 } while (Number != 0);\r
191\r
206b5f51 192 AsciiStrCpyS (Buffer, BufferSize, &TempStr[Index]);\r
dc361cc5 193\r
194 return AsciiStrLen (Buffer);\r
195}\r
196\r
197\r
198/**\r
f737cfb9 199 Convert ASCII numeric string to a UINTN value.\r
dc361cc5 200\r
f737cfb9 201 @param Buffer Pointer to the 8-byte unsigned int value.\r
dc361cc5 202\r
f737cfb9 203 @return UINTN value of the ASCII string.\r
dc361cc5 204\r
205**/\r
206UINT64\r
207AtoU64 (\r
208 IN UINT8 *Buffer\r
209 )\r
210{\r
211 UINT64 Value;\r
212 UINT8 Character;\r
213\r
214 Value = 0;\r
215 while ((Character = *Buffer++) != '\0') {\r
216 Value = MultU64x32 (Value, 10) + (Character - '0');\r
217 }\r
218\r
219 return Value;\r
220}\r
221\r