]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
[Description]:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcSupport.c
CommitLineData
dc361cc5 1/** @file\r
2\r
8792362f 3Copyright (c) 2007 - 2008, Intel Corporation \r
dc361cc5 4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PxeBcSupport.c\r
15\r
16Abstract:\r
17\r
18 Support routines for PxeBc\r
19\r
20\r
21**/\r
22\r
23\r
24#include "PxeBcImpl.h"\r
25\r
26\r
27/**\r
28\r
29 @param Smbios Pointer to SMBIOS structure\r
30 @param StringNumber String number to return. 0 is used to skip all\r
31 strings and point to the next SMBIOS structure.\r
32\r
33 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0\r
34\r
35**/\r
36// GC_NOTO: function comment is missing 'Routine Description:'\r
37CHAR8 *\r
38GetSmbiosString (\r
39 IN SMBIOS_STRUCTURE_POINTER *Smbios,\r
40 IN UINT16 StringNumber\r
41 )\r
42{\r
43 UINT16 Index;\r
44 CHAR8 *String;\r
45\r
46 //\r
47 // Skip over formatted section\r
48 //\r
49 String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r
50\r
51 //\r
52 // Look through unformated section\r
53 //\r
54 for (Index = 1; Index <= StringNumber || StringNumber == 0; Index++) {\r
55 if (StringNumber == Index) {\r
56 return String;\r
57 }\r
58 //\r
59 // Skip string\r
60 //\r
61 for (; *String != 0; String++)\r
62 ;\r
63 String++;\r
64\r
65 if (*String == 0) {\r
66 //\r
67 // If double NULL then we are done.\r
68 // Return pointer to next structure in Smbios.\r
69 // if you pass in a 0 you will always get here\r
70 //\r
71 Smbios->Raw = (UINT8 *)++String;\r
72 return NULL;\r
73 }\r
74 }\r
75\r
76 return NULL;\r
77}\r
78\r
79\r
80/**\r
81 This function gets system guid and serial number from the smbios table\r
82\r
83 @param SystemGuid The pointer of returned system guid\r
84 @param SystemSerialNumber The pointer of returned system serial number\r
85\r
86 @retval EFI_SUCCESS Successfully get the system guid and system serial\r
87 number\r
88 @retval EFI_NOT_FOUND Not find the SMBIOS table\r
89\r
90**/\r
91EFI_STATUS\r
92GetSmbiosSystemGuidAndSerialNumber (\r
93 IN EFI_GUID *SystemGuid,\r
94 OUT CHAR8 **SystemSerialNumber\r
95 )\r
96{\r
97 EFI_STATUS Status;\r
98 SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;\r
99 SMBIOS_STRUCTURE_POINTER Smbios;\r
100 SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r
101 UINT16 Index;\r
102\r
103 Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);\r
104\r
105 if (EFI_ERROR (Status)) {\r
106 return EFI_NOT_FOUND;\r
107 }\r
108\r
109 Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;\r
110 SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);\r
111\r
112 for (Index = 0; Index < SmbiosTable->TableLength; Index++) {\r
113 if (Smbios.Hdr->Type == 1) {\r
114 if (Smbios.Hdr->Length < 0x19) {\r
115 //\r
116 // Older version did not support Guid and Serial number\r
117 //\r
118 continue;\r
119 }\r
120 //\r
121 // SMBIOS tables are byte packed so we need to do a byte copy to\r
122 // prevend alignment faults on Itanium-based platform.\r
123 //\r
124 CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));\r
125 *SystemSerialNumber = GetSmbiosString (&Smbios, Smbios.Type1->SerialNumber);\r
126\r
127 return EFI_SUCCESS;\r
128 }\r
129 //\r
130 // Make Smbios point to the next record\r
131 //\r
132 GetSmbiosString (&Smbios, 0);\r
133\r
134 if (Smbios.Raw >= SmbiosEnd.Raw) {\r
135 //\r
136 // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.\r
137 // given this we must double check against the length of the structure.\r
138 //\r
139 return EFI_SUCCESS;\r
140 }\r
141 }\r
142\r
143 return EFI_SUCCESS;\r
144}\r
145\r
146\r
147/**\r
148 GC_NOTO: Add function description\r
149\r
150 @param Event GC_NOTO: add argument description\r
151 @param Context GC_NOTO: add argument description\r
152\r
153 @return GC_NOTO: add return values\r
154\r
155**/\r
156VOID\r
157PxeBcCommonNotify (\r
158 IN EFI_EVENT Event,\r
159 IN VOID *Context\r
160 )\r
161{\r
162 *((BOOLEAN *) Context) = TRUE;\r
163}\r
164\r
8792362f 165EFI_STATUS\r
166PxeBcConfigureUdpWriteInstance (\r
167 IN EFI_UDP4_PROTOCOL *Udp4,\r
168 IN EFI_IPv4_ADDRESS *StationIp,\r
169 IN EFI_IPv4_ADDRESS *SubnetMask,\r
170 IN EFI_IPv4_ADDRESS *Gateway,\r
171 IN OUT UINT16 *SrcPort\r
172 )\r
173{\r
174 EFI_UDP4_CONFIG_DATA Udp4CfgData;\r
175 EFI_STATUS Status;\r
176\r
177 ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
178\r
179 Udp4CfgData.ReceiveTimeout = 1000;\r
180 Udp4CfgData.TypeOfService = DEFAULT_ToS;\r
181 Udp4CfgData.TimeToLive = DEFAULT_TTL;\r
182\r
183 CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
184 CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r
185\r
186 Udp4CfgData.StationPort = *SrcPort;\r
187\r
188 //\r
189 // Reset the instance.\r
190 //\r
191 Udp4->Configure (Udp4, NULL);\r
192\r
193 Status = Udp4->Configure (Udp4, &Udp4CfgData);\r
194 if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r
195 //\r
196 // basic configuration OK, need to add the default route entry\r
197 //\r
198 Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r
199 if (EFI_ERROR (Status)) {\r
200 //\r
201 // roll back\r
202 //\r
203 Udp4->Configure (Udp4, NULL);\r
204 }\r
205 }\r
206\r
207 if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r
208 Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r
209 *SrcPort = Udp4CfgData.StationPort;\r
210 }\r
211\r
212 return Status;\r
213}\r
214\r
dc361cc5 215\r
216/**\r
217 Convert number to ASCII value\r
218\r
219 @param Number Numeric value to convert to decimal ASCII value.\r
220 @param Buffer Buffer to place ASCII version of the Number\r
221 @param Length Length of Buffer.\r
222\r
223 @retval none none\r
224\r
225**/\r
226VOID\r
227CvtNum (\r
228 IN UINTN Number,\r
229 IN UINT8 *Buffer,\r
230 IN INTN Length\r
231 )\r
232{\r
233 UINTN Remainder;\r
234\r
235 while (Length--) {\r
236 Remainder = Number % 10;\r
237 Number /= 10;\r
238 Buffer[Length] = (UINT8) ('0' + Remainder);\r
239 }\r
240}\r
241\r
242\r
243/**\r
244 GC_NOTO: Add function description\r
245\r
246 @param Number GC_NOTO: add argument description\r
247 @param Buffer GC_NOTO: add argument description\r
248\r
249 @return GC_NOTO: add return values\r
250\r
251**/\r
252UINTN\r
253UtoA10 (\r
254 IN UINTN Number,\r
255 IN CHAR8 *Buffer\r
256 )\r
257{\r
258 UINTN Index;\r
259 CHAR8 TempStr[64];\r
260\r
261 Index = 63;\r
262 TempStr[Index] = 0;\r
263\r
264 do {\r
265 Index--;\r
266 TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r
267 Number = Number / 10;\r
268 } while (Number != 0);\r
269\r
270 AsciiStrCpy (Buffer, &TempStr[Index]);\r
271\r
272 return AsciiStrLen (Buffer);\r
273}\r
274\r
275\r
276/**\r
277 Convert ASCII numeric string to a UINTN value\r
278\r
279 @param Number Numeric value to convert to decimal ASCII value.\r
280 @param Buffer Buffer to place ASCII version of the Number\r
281\r
282 @retval Value UINTN value of the ASCII string.\r
283\r
284**/\r
285UINT64\r
286AtoU64 (\r
287 IN UINT8 *Buffer\r
288 )\r
289{\r
290 UINT64 Value;\r
291 UINT8 Character;\r
292\r
293 Value = 0;\r
294 while ((Character = *Buffer++) != '\0') {\r
295 Value = MultU64x32 (Value, 10) + (Character - '0');\r
296 }\r
297\r
298 return Value;\r
299}\r
300\r